Skip to content

Commit 0997908

Browse files
committed
print the various steps
Let the user know what is happening by printing the high-level steps in the console.
1 parent 44e8a43 commit 0997908

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/nixos-anywhere.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ abort() {
4040
exit 1
4141
}
4242

43+
step() {
44+
echo "### $* ###"
45+
}
46+
4347
default_kexec_url=https://github.com/nix-community/nixos-images/releases/download/nixos-22.11/nixos-kexec-installer-noninteractive-x86_64-linux.tar.gz
4448
kexec_url="$default_kexec_url"
4549
enable_debug=""
@@ -203,6 +207,7 @@ if [[ -n ${SSH_PRIVATE_KEY-} ]]; then
203207
ssh_copy_id_args+=(-f)
204208
fi
205209

210+
step Uploading install SSH keys
206211
until
207212
ssh-copy-id \
208213
-i "$ssh_key_dir"/nixos-anywhere.pub \
@@ -249,6 +254,7 @@ SSH
249254
export $(echo "$filtered_facts" | xargs)
250255
}
251256

257+
step Gathering machine facts
252258
import_facts
253259

254260
if [[ ${has_tar-n} == "n" ]]; then
@@ -273,6 +279,7 @@ if [[ ${is_arch-n} != "x86_64" ]] && [[ $kexec_url == "$default_kexec_url" ]]; t
273279
fi
274280

275281
if [[ ${is_kexec-n} == "n" ]] && [[ ${is_installer-n} == "n" ]]; then
282+
step Switching system into kexec
276283
ssh_ <<SSH
277284
set -efu ${enable_debug}
278285
$maybe_sudo rm -rf /root/kexec
@@ -303,18 +310,20 @@ SSH
303310
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
304311
fi
305312
for path in "${!disk_encryption_keys[@]}"; do
306-
echo "Uploading ${disk_encryption_keys[$path]} to $path"
313+
step "Uploading ${disk_encryption_keys[$path]} to $path"
307314
ssh_ "umask 077; cat > $path" <"${disk_encryption_keys[$path]}"
308315
done
309316

310317
pubkey=$(ssh-keyscan -t ed25519 "${ssh_connection//*@/}" 2>/dev/null | sed -e 's/^[^ ]* //' | base64 -w0)
311318

312319
if [[ -z ${disko_script-} ]] && [[ ${build_on_remote-n} == "y" ]]; then
320+
step Building disko script
313321
disko_script=$(
314322
nix_build "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.disko" \
315323
--builders "ssh://$ssh_connection?base64-ssh-public-host-key=$pubkey&ssh-key=$ssh_key_dir/nixos-anywhere $is_arch-linux"
316324
)
317325
fi
326+
step Formatting hard drive with disko
318327
nix_copy --to "ssh://$ssh_connection" "$disko_script"
319328
ssh_ "$disko_script"
320329

@@ -326,20 +335,24 @@ if [[ ${stop_after_disko-n} == "y" ]]; then
326335
fi
327336

328337
if [[ -z ${nixos_system-} ]] && [[ ${build_on_remote-n} == "y" ]]; then
338+
step Building the system closure
329339
nixos_system=$(
330340
nix_build "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.toplevel" \
331341
--builders "ssh://$ssh_connection?remote-store=local?root=/mnt&base64-ssh-public-host-key=$pubkey&ssh-key=$ssh_key_dir/nixos-anywhere $is_arch-linux"
332342
)
333343
fi
344+
step Uploading the system closure
334345
nix_copy --to "ssh://$ssh_connection?remote-store=local?root=/mnt" "$nixos_system"
335346

336347
if [[ -n ${extra_files-} ]]; then
337348
if [[ -d $extra_files ]]; then
338349
extra_files="$extra_files/"
339350
fi
351+
step Copying extra files
340352
rsync -rlpv -FF -e "ssh -i \"$ssh_key_dir\"/nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" "$extra_files" "${ssh_connection}:/mnt/"
341353
fi
342354

355+
step Installing NixOS
343356
ssh_ <<SSH
344357
set -efu ${enable_debug}
345358
# needed for installation if initrd-secrets are used
@@ -351,7 +364,9 @@ nixos-install --no-root-passwd --no-channel-copy --system "$nixos_system"
351364
nohup bash -c '${maybe_reboot}' >/dev/null &
352365
SSH
353366

354-
# wait for machine to become unreachable due to reboot
355367
if [[ -n ${maybe_reboot} ]]; then
368+
step Waiting for the maching to become reachable again
356369
while timeout_ssh_ -- exit 0; do sleep 1; done
357370
fi
371+
372+
step "Done!"

0 commit comments

Comments
 (0)