@@ -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