Nix Channels
Nixpkgs binary cache
目前 TUNA/BFSU/USTC 等并未提供 nix-darwin 的 binary cache,请使用官方源或 SJTUG。
持久配置
以优先选择镜像,备选源站为例,选择以下配置之一:
-
单独安装的 Nix:编辑配置文件添加或修改如下项(多用户安装修改
/etc/nix/nix.conf,单用户安装修改~/.config/nix/nix.conf):substituters = https://mirrors.ha.edu.cn/nix-channels/store https://cache.nixos.org/ -
NixOS 21.11 及之前的版本在
configuration.nix中使用如下配置(https://cache.nixos.org 会被自动添加)nix.binaryCaches = [ "https://mirrors.ha.edu.cn/nix-channels/store" ]; -
NixOS 22.05 及之后的版本在
configuration.nix中使用如下配置(https://cache.nixos.org 会被自动添加):nix.settings.substituters = [ "https://mirrors.ha.edu.cn/nix-channels/store" ];
如果因为无法访问 https://cache.nixos.org 等原因,希望避免自动添加该默认地址,请在配置中使用lib.mkForce。
# load `lib` into namespace at the file head with `{ config, pkgs, lib, ... }:`
nix.settings.substituters = lib.mkForce [ "https://mirrors.ha.edu.cn/nix-channels/store" ];
Nix 2.4 及之后的版本可以在 substituter 链接参数中指定优先级 (1~100):
nix.settings.substituters = [ "https://mirrors.ha.edu.cn/nix-channels/store?priority=10" ];
查询 substituter 默认优先级:
curl https://mirrors.ha.edu.cn/nix-channels/store/nix-cache-info
一般情况下,镜像的默认优先级为 40,与 cache.nixos.org 保持一致。
临时使用
在安装 NixOS 时临时使用:
nixos-install --option substituters "https://mirrors.ha.edu.cn/nix-channels/store https://cache.nixos.org"
在 NixOS 切换配置时临时使用:
nixos-rebuild --option substituters "https://mirrors.ha.edu.cn/nix-channels/store https://cache.nixos.org"
临时关闭可以通过还原 substituters 实现:
nixos-rebuild --option substituters "https://cache.nixos.org"nixos-rebuild --option substituters "https://cache.nixos.org"
指定 substituter 优先级:
nixos-rebuild --option substituters "https://mirrors.ha.edu.cn/nix-channels/store?priority=10 https://cache.nixos.org"
Nixpkgs channel
注:SJTUG 提供了 binary cache,未提供该镜像。
单独安装的 Nix 替换 nixpkgs-unstable 命令如下:
nix-channel --add https://mirrors.ha.edu.cn/nix-channels/nixpkgs-unstable nixpkgs
nix-channel --update
替换 NixOS channel 命令如下(以 root 执行):
nix-channel --add https://mirrors.ha.edu.cn/nix-channels/nixos-25.05 nixos
nix-channel --update