NixOS 常用命令
安装程序
- 使用
nix-env安装的包不会被自动记录到 Nix 的声明式配置中 - New CLI 中对应命令为
nix profile
nix-shell一般用于临时使用某个包,退出 shell 后不会污染环境。
nix-shell -p hello
# 带 nix 语句的命令
nix-shell -p 'python38.withPackages (packages: [ packages.django ])'
处理 nix store
- 使用
nix-store手动处理 nix store。 - 构建指定的 path,输入的 path 可以是 derivation
nix-instantiate- 通过有输出 derivation 的文件实例化为一个 drv 文件
垃圾回收
# 查询所有历史版本
nix profile history --profile /nix/var/nix/profiles/system
# 清理历史版本,不会删除数据
nix profile wipe-history --older-than 7d --profile /nix/var/nix/profiles/system
# `-d` 指示删除 `/nix/var/nix/profiles` 下所有的 old generations
nix-collect-garbage -d
更新配置
- 使用镜像更新
home-manager switch --flake ".#$(hostname)" --impure --option substituters "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
nix flake check --option substituters "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
调试 Nix 表达式
- 常用命令
:lf <ref>和:e <expr>
同步 flake 版本
使当前 flake 与系统版本同步
更新单个 input
其它命令
查看当前配置 nix show-config
查看 flake 的 drv
比较两个 closures
evaluate outPath
References
nix.dev
Haskell for all: How to correctly cache build-time dependencies using Nix