Nix Snippets
Rust
Rust bindgen
Using rust-bindgen in Nix > nixpkgs/pkgs/applications/networking/browsers/firefox/common.nix at 1fab95f5190d087e66a3502481e34e15d62090aa · NixOS/nixpkgs · GitHub > nix-env to build cloudflare/boring · GitHub > nixpkgs/doc/languages-frameworks/rust.section.md at master · NixOS/nixpkgs · GitHub
Rust buildPackage
naive method
packages.fromNaive = with pkgs;
rustPlatform.buildRustPackage {
pname = "package-name";
inherit ((lib.importTOML ./Cargo.toml).package) version;
doCheck = false;
src = lib.cleanSource ./.;
cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};
buildInputs = [
clang
gcc.cc.lib
];
nativeBuildInputs = [
pkg-config
rustPlatform.bindgenHook
];
inherit env;
};
启用 swap
zramSwap.memoryPercent 默认参数是 50,使用 zramctl 查看分配大小
pkgs overlay
overlay 的参数中,final 为覆盖后的 pkgs,prev 为覆盖前的 pkgs
Derivation
- evaluate derivation in REPL
fetchers
path filter
Working with local files — nix.dev documentation > Nixpkgs Reference Manual
docs = builtins.path {
path = ./.;
filter = path: type:
builtins.elem (/. + path) [
./README.md
];
};
docs = with pkgs.lib.fileset;
toSource {
root = ./.;
fileset = unions [
(fileFilter (file: file.hasExt "md") ./.)
];
};
Enabling CUDA in Pytorch
- GitHub - nix-community/nix-ld: Run unpatched dynamic binaries on NixOS [maintainer=@Mic92]
- 虚拟环境下的 Python 需要手动设置
LD_LIBRARY_PATH
- Compatibility with Tensorflow - 从源代码构建 | TensorFlow