Skip to content

Commit 3de4f12

Browse files
authored
Merge pull request #575 from nix-community/push-krzlkykyknrl
nixos-anywhere: fix running `nixos-facter` when it isn't installed
2 parents bc653a8 + d239ac6 commit 3de4f12

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/nixos-anywhere.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,16 +581,19 @@ generateHardwareConfig() {
581581
mkdir -p "$(dirname "$hardwareConfigPath")"
582582
case "$hardwareConfigBackend" in
583583
nixos-facter)
584-
if [[ ${isInstaller} == "y" ]]; then
585-
maybeSudo=""
586-
fi
587584
if [[ ${hasNixOSFacter} == "n" ]]; then
588585
step "Generating facter.json using nixos-facter from nixpkgs"
586+
587+
# We need to quote all the flags before they get passed to SSH
588+
# otherwise SSH will drop the quotes which is necessary for
589+
# `--extra-experimental-features "nix-command flakes"`.
590+
# We can use the following Bash-ism described at: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion-1
591+
# For more information: https://unix.stackexchange.com/questions/379181/escape-a-variable-for-use-as-content-of-another-script
589592
runSshNoTty -o ConnectTimeout=10 \
590-
nix run nixpkgs#nixos-facter "${nixOptions[@]}" >"$hardwareConfigPath"
593+
nix shell "${nixOptions[@]@Q}" nixpkgs#nixos-facter -c ${maybeSudo} nixos-facter >"$hardwareConfigPath"
591594
else
592595
step "Generating facter.json using nixos-facter"
593-
runSshNoTty -o ConnectTimeout=10 "${maybeSudo}" "nixos-facter" >"$hardwareConfigPath"
596+
runSshNoTty -o ConnectTimeout=10 ${maybeSudo} nixos-facter >"$hardwareConfigPath"
594597
fi
595598
;;
596599
nixos-generate-config)
@@ -698,6 +701,9 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr
698701
# After kexec we explicitly set the user to root@
699702
sshConnection="root@${sshHost}"
700703
704+
# TODO: remove this after we reimport facts post-kexec and set this as a fact
705+
maybeSudo=""
706+
701707
# waiting for machine to become available again
702708
until runSsh -o ConnectTimeout=10 -- exit 0; do sleep 5; done
703709
}

0 commit comments

Comments
 (0)