From 37af3fcd5ff65ab4ac85d476a5600f9231f15e37 Mon Sep 17 00:00:00 2001 From: Yinhao Huang <64564727+nmnmcc@users.noreply.github.com> Date: Wed, 20 May 2026 21:05:39 +0800 Subject: [PATCH] =?UTF-8?q?nixos:=20=E9=85=8D=E7=BD=AE=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E6=97=B6=20substituters=20(#619)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trans.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/trans.sh b/trans.sh index 991ba99..a67ee5a 100644 --- a/trans.sh +++ b/trans.sh @@ -1682,6 +1682,21 @@ install_nixos() { export USER=root export HOME=/root + configure_nix_substituters() { + if ! is_in_china; then + return + fi + + nix_conf=/etc/nix/nix.conf + mkdir -p "$(dirname "$nix_conf")" + + if [ -f "$nix_conf" ]; then + sed -i '/^[[:space:]]*substituters[[:space:]]*=/d' "$nix_conf" + fi + + echo "substituters = $mirror/store" >>"$nix_conf" + } + case "$nix_from" in alpine) apk add nix @@ -1690,9 +1705,7 @@ install_nixos() { # https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/community/nix/APKBUILD#L125 sed -i '/max-jobs/d' /etc/nix/nix.conf echo "max-jobs = $threads" >>/etc/nix/nix.conf - if is_in_china; then - echo "substituters = $mirror/store" >>/etc/nix/nix.conf - fi + configure_nix_substituters rc-service -q nix-daemon restart # 添加 nix-env 安装的软件到 PATH PATH="/root/.nix-profile/bin:$PATH" @@ -1743,6 +1756,7 @@ install_nixos() { apk del xz # shellcheck source=/dev/null . /root/.nix-profile/etc/profile.d/nix.sh + configure_nix_substituters ;; esac