@@ -473,7 +473,7 @@ importFacts() {
473
473
done
474
474
}
475
475
476
- canBuildLocally () {
476
+ checkBuildLocally () {
477
477
local system extraPlatforms machineSystem
478
478
system=" $( nix --extra-experimental-features ' nix-command flakes' config show system) "
479
479
extraPlatforms=" $( nix --extra-experimental-features ' nix-command flakes' config show extra-platforms) "
@@ -485,32 +485,33 @@ canBuildLocally() {
485
485
else
486
486
machineSystem=" $( nix --extra-experimental-features ' nix-command flakes' eval --raw " ${flake} " # "${flakeAttr}".pkgs.system 2>/dev/null || echo "unknown")"
487
487
if [[ ${machineSystem} == " unknown" ]]; then
488
+ buildOn=auto
488
489
return
489
490
fi
490
491
fi
491
492
492
493
if [[ ${system} == " ${machineSystem} " ]]; then
494
+ buildOn=local
493
495
return
494
496
fi
495
497
496
498
if [[ ${extraPlatforms} == " *${machineSystem} *" ]]; then
499
+ buildOn=local
497
500
return
498
501
fi
499
502
500
- local entropy nonSubstitutableDrv
503
+ local entropy
501
504
entropy=" $( date +' %Y%m%d%H%M%S' ) "
502
- nonSubstitutableDrv=$( nix eval \
503
- --impure \
504
- --raw \
505
+ if nix build \
505
506
-L \
506
507
" ${nixOptions[@]} " \
507
508
--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
511
510
# The local build failed
512
- export buildOn=remote
511
+ buildOn=local
513
512
fi
513
+
514
+ buildOn=remote
514
515
}
515
516
516
517
generateHardwareConfig () {
@@ -708,7 +709,7 @@ main() {
708
709
fi
709
710
710
711
if [[ ${buildOn} == " auto" ]]; then
711
- canBuildLocally
712
+ checkBuildLocally
712
713
fi
713
714
714
715
# parse flake nixos-install style syntax, get the system attr
@@ -778,11 +779,15 @@ main() {
778
779
# Before we do not have a valid hardware configuration we don't know the machine system
779
780
if [[ ${buildOn} == " auto" ]]; then
780
781
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
783
788
fi
784
789
785
- if [[ ${buildOn} != " remote" ]] && [[ -n ${flake} ]] && [[ ${hardwareConfigBackend} != " none " ]]; then
790
+ if [[ ${buildOn} != " remote" ]] && [[ -n ${flake} ]] && [[ -z ${diskoScript} ]]; then
786
791
if [[ ${phases[disko]} == 1 ]]; then
787
792
diskoScript=$( nixBuild " ${flake} #${flakeAttr} .system.build.${diskoMode} Script" )
788
793
fi
0 commit comments