binary cache 默认用的是 https://cache.nixos.org ,在国内访问很慢。需要替换成镜像源,以中科大源为例。
注意点:
binaryCaches
选项在最新版本的 nix 已弃用,请使用substituters
。https://cache.nixos.org
会自动添加到列表,无须用户自己写上。substituters
配置只适用于 root 用户,非 root 用户会提示ignoring untrusted substituter '...', you are not a trusted user.
。
解决方法:
- 如果你使用
nix.conf
,用trusted-substituters
代替substituters
。
trusted-substituters = https://mirrors.ustc.edu.cn/nix-channels/store
- 如果你使用 nix flake,用
nix.settings.trusted-substituters
替换nix.settings.substituters
。
nix.settings.trusted-substituters = ["https://mirrors.ustc.edu.cn/nix-channels/store"];
原因:flake.nix 不是完整的 nix 语言。某些情况使用 import 语法会报这个错。详见 NixOS/nix#4945
目前社区有三种 formatter
具体使用方法见 https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-fmt
我选择 alejandra 的原因。
nixpkgs 有两个包:bashInteractive 和 bash。它们的区别是:
- bashInteractive = 带 Readline 功能的 bash。
- bash = 没有 Readline 功能的 bash。
一般用户应该选用 bashInteractive。快捷键功能才能正常使用。
参考 Issue。