@@ -231,20 +231,20 @@ if [[ ${substitute_on_destination-n} == "y" ]]; then
231
231
fi
232
232
233
233
# ssh wrapper
234
- timeout_ssh_ () {
234
+ runSSHTimeout () {
235
235
timeout 10 ssh -i " $ssh_key_dir " /nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " ${ssh_args[@]} " " $ssh_connection " " $@ "
236
236
}
237
- ssh_ () {
237
+ runSSH () {
238
238
ssh " $ssh_tty_param " -i " $ssh_key_dir " /nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " ${ssh_args[@]} " " $ssh_connection " " $@ "
239
239
}
240
240
241
- nix_copy () {
241
+ nixCopy () {
242
242
NIX_SSHOPTS=" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $ssh_key_dir /nixos-anywhere ${ssh_args[*]} " nix copy \
243
243
" ${nix_options[@]} " \
244
244
" ${nix_copy_options[@]} " \
245
245
" $@ "
246
246
}
247
- nix_build () {
247
+ nixBuild () {
248
248
NIX_SSHOPTS=" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $ssh_key_dir /nixos-anywhere ${ssh_args[*]} " nix build \
249
249
--print-out-paths \
250
250
--no-link \
@@ -294,8 +294,8 @@ if [[ -n ${flake-} ]]; then
294
294
" ${nix_options[@]} " \
295
295
" ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.installTest"
296
296
fi
297
- disko_script=$( nix_build " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.diskoScript" )
298
- nixos_system=$( nix_build " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.toplevel" )
297
+ disko_script=$( nixBuild " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.diskoScript" )
298
+ nixos_system=$( nixBuild " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.toplevel" )
299
299
fi
300
300
elif [[ -n ${disko_script-} ]] && [[ -n ${nixos_system-} ]]; then
301
301
if [[ -n ${vm_test-} ]]; then
@@ -362,7 +362,7 @@ uploadSSHKey() {
362
362
importFacts () {
363
363
step Gathering machine facts
364
364
local facts filtered_facts
365
- if ! facts=$( ssh_ -o ConnectTimeout=10 enable_debug=$enable_debug sh -- < " $here " /get-facts.sh) ; then
365
+ if ! facts=$( runSSH -o ConnectTimeout=10 enable_debug=$enable_debug sh -- < " $here " /get-facts.sh) ; then
366
366
exit 1
367
367
fi
368
368
filtered_facts=$( echo " $facts " | grep -E ' ^(has|is)_[a-z0-9_]+=\S+' )
@@ -392,7 +392,7 @@ runKexec() {
392
392
fi
393
393
394
394
step Switching system into kexec
395
- ssh_ sh << SSH
395
+ runSSH sh << SSH
396
396
set -efu ${enable_debug}
397
397
$maybe_sudo rm -rf /root/kexec
398
398
$maybe_sudo mkdir -p /root/kexec
@@ -404,16 +404,16 @@ SSH
404
404
fi
405
405
406
406
if [[ -f $kexec_url ]]; then
407
- ssh_ " ${maybe_sudo} tar -C /root/kexec -xvzf-" < " $kexec_url "
407
+ runSSH " ${maybe_sudo} tar -C /root/kexec -xvzf-" < " $kexec_url "
408
408
elif [[ ${has_curl-n} == " y" ]]; then
409
- ssh_ " curl --fail -Ss -L '${kexec_url} ' | ${maybe_sudo} tar -C /root/kexec -xvzf-"
409
+ runSSH " curl --fail -Ss -L '${kexec_url} ' | ${maybe_sudo} tar -C /root/kexec -xvzf-"
410
410
elif [[ ${has_wget-n} == " y" ]]; then
411
- ssh_ " wget '${kexec_url} ' -O- | ${maybe_sudo} tar -C /root/kexec -xvzf-"
411
+ runSSH " wget '${kexec_url} ' -O- | ${maybe_sudo} tar -C /root/kexec -xvzf-"
412
412
else
413
- curl --fail -Ss -L " ${kexec_url} " | ssh_ " ${maybe_sudo} tar -C /root/kexec -xvzf-"
413
+ curl --fail -Ss -L " ${kexec_url} " | runSSH " ${maybe_sudo} tar -C /root/kexec -xvzf-"
414
414
fi
415
415
416
- ssh_ << SSH
416
+ runSSH << SSH
417
417
TMPDIR=/root/kexec setsid ${maybe_sudo} /root/kexec/kexec/run --kexec-extra-flags "${kexec_extra_flags} "
418
418
SSH
419
419
@@ -426,66 +426,66 @@ SSH
426
426
done
427
427
428
428
# wait for machine to become unreachable.
429
- while timeout_ssh_ -- exit 0; do sleep 1; done
429
+ while runSshTimeout -- exit 0; do sleep 1; done
430
430
431
431
# After kexec we explicitly set the user to root@
432
432
ssh_connection=" root@${ssh_host} "
433
433
434
434
# waiting for machine to become available again
435
- until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
435
+ until runSSH -o ConnectTimeout=10 -- exit 0; do sleep 5; done
436
436
fi
437
437
}
438
438
439
439
runDisko () {
440
440
local disko_script=$1
441
441
for path in " ${! disk_encryption_keys[@]} " ; do
442
442
step " Uploading ${disk_encryption_keys[$path]} to $path "
443
- ssh_ " umask 077; cat > $path " < " ${disk_encryption_keys[$path]} "
443
+ runSSH " umask 077; cat > $path " < " ${disk_encryption_keys[$path]} "
444
444
done
445
445
if [[ -n ${disko_script-} ]]; then
446
- nix_copy --to " ssh://$ssh_connection " " $disko_script "
446
+ nixCopy --to " ssh://$ssh_connection " " $disko_script "
447
447
elif [[ ${build_on_remote-n} == " y" ]]; then
448
448
step Building disko script
449
449
# We need to do a nix copy first because nix build doesn't have --no-check-sigs
450
- nix_copy --to " ssh-ng://$ssh_connection " " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.diskoScript" \
450
+ nixCopy --to " ssh-ng://$ssh_connection " " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.diskoScript" \
451
451
--derivation --no-check-sigs
452
452
disko_script=$(
453
- nix_build " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.diskoScript" \
453
+ nixBuild " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.diskoScript" \
454
454
--eval-store auto --store " ssh-ng://$ssh_connection ?ssh-key=$ssh_key_dir /nixos-anywhere"
455
455
)
456
456
fi
457
457
458
458
step Formatting hard drive with disko
459
- ssh_ " $disko_script "
459
+ runSSH " $disko_script "
460
460
}
461
461
462
462
nixosInstall () {
463
463
if [[ -n ${nixos_system-} ]]; then
464
464
step Uploading the system closure
465
- nix_copy --to " ssh://$ssh_connection ?remote-store=local?root=/mnt" " $nixos_system "
465
+ nixCopy --to " ssh://$ssh_connection ?remote-store=local?root=/mnt" " $nixos_system "
466
466
elif [[ ${build_on_remote-n} == " y" ]]; then
467
467
step Building the system closure
468
468
# We need to do a nix copy first because nix build doesn't have --no-check-sigs
469
- nix_copy --to " ssh-ng://$ssh_connection ?remote-store=local?root=/mnt" " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.toplevel" \
469
+ nixCopy --to " ssh-ng://$ssh_connection ?remote-store=local?root=/mnt" " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.toplevel" \
470
470
--derivation --no-check-sigs
471
471
nixos_system=$(
472
- nix_build " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.toplevel" \
472
+ nixBuild " ${flake} #nixosConfigurations.\" ${flakeAttr} \" .config.system.build.toplevel" \
473
473
--eval-store auto --store " ssh-ng://$ssh_connection ?ssh-key=$ssh_key_dir /nixos-anywhere&remote-store=local?root=/mnt"
474
474
)
475
475
fi
476
476
477
477
if [[ -n ${extra_files-} ]]; then
478
478
step Copying extra files
479
- tar -C " $extra_files " -cpf- . | ssh_ " ${maybe_sudo} tar -C /mnt -xf- --no-same-owner"
480
- ssh_ " chmod 755 /mnt" # tar also changes permissions of /mnt
479
+ tar -C " $extra_files " -cpf- . | runSSH " ${maybe_sudo} tar -C /mnt -xf- --no-same-owner"
480
+ runSSH " chmod 755 /mnt" # tar also changes permissions of /mnt
481
481
fi
482
482
483
483
step Installing NixOS
484
484
maybeReboot=" "
485
485
if [[ ${phases[reboot]-} == 1 ]]; then
486
486
maybeReboot=" nohup sh -c 'sleep 6 && reboot' >/dev/null &"
487
487
fi
488
- ssh_ sh << SSH
488
+ runSSH sh << SSH
489
489
set -eu ${enable_debug}
490
490
# when running not in nixos we might miss this directory, but it's needed in the nixos chroot during installation
491
491
export PATH="\$ PATH:/run/current-system/sw/bin"
547
547
# Switch to root user by copying authorized_keys.
548
548
if [[ ${is_installer-n} == " y" ]] && [[ ${ssh_user} != " root" ]]; then
549
549
# Allow copy to fail if authorized_keys does not exist, like if using /etc/ssh/authorized_keys.d/
550
- ssh_ " ${maybe_sudo} mkdir -p /root/.ssh; ${maybe_sudo} cp ~/.ssh/authorized_keys /root/.ssh || true"
550
+ runSSH " ${maybe_sudo} mkdir -p /root/.ssh; ${maybe_sudo} cp ~/.ssh/authorized_keys /root/.ssh || true"
551
551
ssh_connection=" root@${ssh_host} "
552
552
fi
553
553
561
561
562
562
if [[ ${phases[reboot]-} == 1 ]]; then
563
563
step Waiting for the machine to become unreachable due to reboot
564
- while timeout_ssh_ -- exit 0; do sleep 1; done
564
+ while runSshTimeout -- exit 0; do sleep 1; done
565
565
fi
566
566
567
567
step " Done!"
0 commit comments