Skip to content

Commit 9fd3610

Browse files
committed
feat: Fallback to nixpkgs#nixos-facter if not available in booted system
Fallback to `nixos-facter` from `nixpkgs` if not available in the booted system. This way we can skip the specific image requirement, while still supporting the specific `nixos-facter` in a booted image, if `available`. Can improve bootstrapping of `nixos-anywhere`. Alternatives: - Since this implementation directly runs `nixos-facter` from `nixpkgs` we could theoretically get an uncached version and would need to build. We could test for that with `--max-jobs 0` and give an approriate error message.
1 parent d00d5b7 commit 9fd3610

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/nixos-anywhere.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,17 @@ generateHardwareConfig() {
582582
case "$hardwareConfigBackend" in
583583
nixos-facter)
584584
if [[ ${isInstaller} == "y" ]]; then
585-
if [[ ${hasNixOSFacter} == "n" ]]; then
586-
abort "nixos-facter is not available in booted installer, use nixos-generate-config. For nixos-facter, you may want to boot an installer image from here instead: https://github.com/nix-community/nixos-images"
587-
fi
588-
else
589585
maybeSudo=""
590586
fi
587+
if [[ ${hasNixOSFacter} == "n" ]]; then
588+
step "Generating hardware-configuration.nix using nixos-facter from nixpkgs"
589+
runSshNoTty -o ConnectTimeout=10 "${maybeSudo}" \
590+
nix run "${nixOptions[@]}" \
591+
nixpkgs#nixos-facter >"$hardwareConfigPath"
592+
else
593+
step "Generating hardware-configuration.nix using nixos-facter"
594+
runSshNoTty -o ConnectTimeout=10 "${maybeSudo}" "nixos-facter" >"$hardwareConfigPath"
595+
fi
591596
592597
step "Generating hardware-configuration.nix using nixos-facter"
593598
runSshNoTty -o ConnectTimeout=10 ${maybeSudo} "nixos-facter" >"$hardwareConfigPath"

0 commit comments

Comments
 (0)