<aside> <img src="notion://custom_emoji/9040cc52-5c24-4c85-8328-7061a24dd7f9/1bbd969b-881f-8008-86d9-007a40b8d4f9" alt="notion://custom_emoji/9040cc52-5c24-4c85-8328-7061a24dd7f9/1bbd969b-881f-8008-86d9-007a40b8d4f9" width="40px" />
Nix + Flake 是当前流行的依赖控制方案。
Flake
</aside>
<aside> <img src="notion://custom_emoji/9040cc52-5c24-4c85-8328-7061a24dd7f9/1bbd969b-881f-8008-86d9-007a40b8d4f9" alt="notion://custom_emoji/9040cc52-5c24-4c85-8328-7061a24dd7f9/1bbd969b-881f-8008-86d9-007a40b8d4f9" width="40px" />
Some info
Channel
stable 通道一般使用LTS或稳定版 软件包,比如(20250319)Python3.12
unstable 通道则发布更多新版软件包,比如(20250319)Python3.13
https://channels.nixos.org/?prefix=
https://nix.dev/manual/nix/2.24/command-ref/nix-channel.html
nix 添加本地channel的指令(原生)
nix-channel --add <https://nixos.org/channels/nixpkgs-unstable> nixpkgs-unstable
nix-channel --update
开发环境
flake
<aside> <img src="notion://custom_emoji/9040cc52-5c24-4c85-8328-7061a24dd7f9/1bbd969b-881f-8008-86d9-007a40b8d4f9" alt="notion://custom_emoji/9040cc52-5c24-4c85-8328-7061a24dd7f9/1bbd969b-881f-8008-86d9-007a40b8d4f9" width="40px" />
Flakes 需要配合git使用。 项目源文件commit到git branch 后再进行flake操作:flake只追踪git 追踪的文件,本地配置文件需要额外操作。 </aside>
# For multi-user installations (requires sudo)
sudo mkdir -p /etc/nix
echo 'experimental-features = nix-command flakes' | sudo tee -a /etc/nix/nix.conf
sudo systemctl restart nix-daemon
collect-garbage 清理nix缓存
nix-collect-garbage
nix store gc
https://www.reddit.com/r/NixOS/comments/1bxa6dc/noob_question_how_to_install_software_from_github/
nix flake update --show-trace
nix develop
nix-shell -p gh
mkdir -p ~/.config/nix
echo "access-tokens = github.com=$(gh auth token)" > ~/.config/nix/nix.conf
cat ~/.config/nix/nix.conf
chmod 600 ~/.config/nix/nix.conf
这个 token 会在几小时后过期(GitHub CLI 的默认 token 有效期),如果需要长期有效的 token:
gh auth token --hostname github.com --scopes repo
获取长期 token