Skip to content

Commit b5cc26d

Browse files
committed
fix various build-on remote bugs
1 parent f4849b2 commit b5cc26d

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/nixos-anywhere.sh

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ importFacts() {
473473
done
474474
}
475475

476-
canBuildLocally() {
476+
checkBuildLocally() {
477477
local system extraPlatforms machineSystem
478478
system="$(nix --extra-experimental-features 'nix-command flakes' config show system)"
479479
extraPlatforms="$(nix --extra-experimental-features 'nix-command flakes' config show extra-platforms)"
@@ -485,32 +485,33 @@ canBuildLocally() {
485485
else
486486
machineSystem="$(nix --extra-experimental-features 'nix-command flakes' eval --raw "${flake}"#"${flakeAttr}".pkgs.system 2>/dev/null || echo "unknown")"
487487
if [[ ${machineSystem} == "unknown" ]]; then
488+
buildOn=auto
488489
return
489490
fi
490491
fi
491492
492493
if [[ ${system} == "${machineSystem}" ]]; then
494+
buildOn=local
493495
return
494496
fi
495497
496498
if [[ ${extraPlatforms} == "*${machineSystem}*" ]]; then
499+
buildOn=local
497500
return
498501
fi
499502
500-
local entropy nonSubstitutableDrv
503+
local entropy
501504
entropy="$(date +'%Y%m%d%H%M%S')"
502-
nonSubstitutableDrv=$(nix eval \
503-
--impure \
504-
--raw \
505+
if nix build \
505506
-L \
506507
"${nixOptions[@]}" \
507508
--expr \
508-
"((builtins.getFlake \"$flake\").inputs.nixpkgs.legacyPackages.$system.runCommandNoCC \"nixos-anywhere-can-build-$entropy\" { } \"echo > \$out\").drvPath")
509-
510-
if ! nix build "${nixOptions[@]}" "${nonSubstitutableDrv}^*"; then
509+
"derivation { system = \"$system\"; name = \"env-$entropy\"; builder = \"/bin/sh\"; args = [ \"-c\" \"echo > \$out\" ]; }"; then
511510
# The local build failed
512-
export buildOn=remote
511+
buildOn=local
513512
fi
513+
514+
buildOn=remote
514515
}
515516
516517
generateHardwareConfig() {
@@ -708,7 +709,7 @@ main() {
708709
fi
709710
710711
if [[ ${buildOn} == "auto" ]]; then
711-
canBuildLocally
712+
checkBuildLocally
712713
fi
713714
714715
# parse flake nixos-install style syntax, get the system attr
@@ -778,11 +779,15 @@ main() {
778779
# Before we do not have a valid hardware configuration we don't know the machine system
779780
if [[ ${buildOn} == "auto" ]]; then
780781
local remoteSystem
781-
remoteSystem=$(runSsh -o ConnectTimeout=10 nix --extra-experimental-features 'nix-command flakes' config show system)
782-
canBuildLocally "${remoteSystem}"
782+
remoteSystem=$(runSshNoTty -o ConnectTimeout=10 nix --extra-experimental-features nix-command config show system)
783+
checkBuildLocally "${remoteSystem}"
784+
# if we cannot figure it out at this point, we will build on the remote host
785+
if [[ ${buildOn} == "auto" ]]; then
786+
buildOn=remote
787+
fi
783788
fi
784789
785-
if [[ ${buildOn} != "remote" ]] && [[ -n ${flake} ]] && [[ ${hardwareConfigBackend} != "none" ]]; then
790+
if [[ ${buildOn} != "remote" ]] && [[ -n ${flake} ]] && [[ -z ${diskoScript} ]]; then
786791
if [[ ${phases[disko]} == 1 ]]; then
787792
diskoScript=$(nixBuild "${flake}#${flakeAttr}.system.build.${diskoMode}Script")
788793
fi

0 commit comments

Comments
 (0)