Files

60 lines
1.6 KiB
Nix

{
description = "A Nix-flake-based Rust development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
utils,
}:
utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
in
{
devShells.default = pkgs.mkShell {
# 编译工具
nativeBuildInputs = with pkgs; [
pkg-config
rustc
cargo
cargo-watch
cargo-edit
cargo-outdated
];
# 运行时动态链接库
buildInputs = with pkgs; [
openssl
alsa-lib
onnxruntime # <- 新增:NixOS 官方封装的 ONNX Runtime
];
shellHook = ''
# 1. 告诉 ort 库:我已经有系统级的 onnxruntime 了,不要去在线下载
export ORT_STRATEGY="system"
# 2. 让 rust-analyzer / rustc 能找到标准库源码
export RUST_SRC_PATH="${pkgs.rustPlatform.rustLibSrc}"
# 3. 指定 onnxruntime 的动态库和头文件路径(供编译时链接)
export ORT_LIB_DIR="${pkgs.onnxruntime}/lib"
export ORT_INCLUDE_DIR="${pkgs.onnxruntime}/include"
# 4. 运行时让程序能通过 LD_LIBRARY_PATH 找到 .so 文件
export LD_LIBRARY_PATH="${pkgs.onnxruntime}/lib:${pkgs.openssl}/lib:${pkgs.alsa-lib}/lib:$LD_LIBRARY_PATH"
echo "🦀 Rust + ALSA + ONNX 环境已就绪!"
'';
};
}
);
}