Skip to content

Commit ff87db6

Browse files
authored
Merge pull request #554 from nix-community/push-rtpwvpmwsylv
nixos-anywhere: set up `substituters` from target machine in installer
2 parents d487afc + 11d5187 commit ff87db6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/nixos-anywhere.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ nixOptions=(
2121
"--no-write-lock-file"
2222
)
2323
SSH_PRIVATE_KEY=${SSH_PRIVATE_KEY-}
24+
machineSubstituters="y"
2425

2526
declare -A phases
2627
phases[kexec]=1
@@ -116,6 +117,9 @@ Options:
116117
after kexec but before installation. Can be repeated.
117118
* --no-substitute-on-destination
118119
disable passing --substitute-on-destination to nix-copy
120+
implies --no-use-machine-substituters
121+
* --no-use-machine-substituters
122+
don't copy the substituters from the machine to be installed into the installer environment
119123
* --debug
120124
enable debug output
121125
* --show-trace
@@ -332,6 +336,10 @@ parseArgs() {
332336
;;
333337
--no-substitute-on-destination)
334338
substituteOnDestination=n
339+
machineSubstituters=n
340+
;;
341+
--no-use-machine-substituters)
342+
machineSubstituters=n
335343
;;
336344
--build-on-remote)
337345
echo "WARNING: --build-on-remote is deprecated, use --build-on remote instead" 2>&1
@@ -906,6 +914,18 @@ main() {
906914
sshConnection="root@${sshHost}"
907915
fi
908916
917+
# Get substituters from the machine and add them to the installer
918+
if [[ ${machineSubstituters} == "y" && -n ${flake} ]]; then
919+
substituters=$(nix --extra-experimental-features 'nix-command flakes' eval --apply toString "${flake}"#"${flakeAttr}".nix.settings.substituters)
920+
trustedPublicKeys=$(nix --extra-experimental-features 'nix-command flakes' eval --apply toString "${flake}"#"${flakeAttr}".nix.settings.trusted-public-keys)
921+
922+
runSsh sh <<SSH || true
923+
mkdir -p ~/.config/nix
924+
echo "extra-substituters = ${substituters}" >> ~/.config/nix/nix.conf
925+
echo "extra-trusted-public-keys = ${trustedPublicKeys}" >> ~/.config/nix/nix.conf
926+
SSH
927+
fi
928+
909929
if [[ ${phases[disko]} == 1 ]]; then
910930
runDisko "$diskoScript"
911931
fi

0 commit comments

Comments
 (0)