A few other things:
--target-host and building locally--all runs builds in parallel across all hosts with an ending reportcomplete and checking
exit_code on external commands as well as using conditionals for things
like 'lib-notify' etc.I doubt this is the final version but I spent too long on it lol…
3CJ46F2EWV5MKVQODGD2O4UX6QKMUW6UO7HUSOGNG7WE3MRFL2QQC WMG2YNWEKFK4DMH3AZP5WSGJ4K66OUHXGK4KPHOW2JNU57DVS42QC GHDLEJRUSCOWDN7GE5J5HAD5J32QCP72LLYE5IHNCJE36WANV2CAC YQHYDW47JG225XJX56JC2BKU6A7KCTQ7BZEZCSI2EJCCTLCUBUVQC 5G7WRBMWKG6DMCOHE6WQHTYZACUHO2UPBZRWN72CFH7P45NN5E7QC MQT74AV47PUYNCX27OMFK6BFN7PP4DX46JAACN2EPRYXUXV7EL3AC HAJVDLU5KQ3CM5P6Z3SOIRHVUTU427EVFA4QHL56MQ3SDRZWK56AC ONBYJCY7FHCMAC7HNI7USLRJTY4TVKWMLACTEDTINLEVBGSSCECAC UB24NMKYJFDSBQN75K336PTTZJ6XMCWRJZSM74UGDPNNGGBUJ4NAC UBB7TTAXVPQQCOVHACKWXSPV2NPARSHREYJB6J3RSEDZZIXPFGOAC BNATIEWPGKROBJ2IA7SSFK2F5T4643LSK7GKOOM2BYEOLMYKWSDQC #!/usr/bin/env nu# nu-lint-ignore: print_and_return_datadef print-notify [message: string]: nothing -> nothing {print $"(ansi purple)[Rebuilder](ansi rst) ($message)\r"if (which notify-send | is-not-empty) {notify-send Rebuilder $message}}def --wrapped rsync-files [...rest: string]: string -> string {(rsync--archive--compress--delete --recursive --force--delete-excluded--delete-missing-args--human-readable--delay-updates...$rest)}def remote-build [target: string--quiet]: nothing -> record {print-notify $"Attempting to start remote build process on ($target)."if not $quiet { print-notify $"Removing old configuration files on ($target)." }(ssh -qtt $"jam@($target)" "rm --recursive --force nixos" | complete)if not $quiet { print-notify $"Copying new configuration files to ($target)." }(jj file list | rsync-files --files-from - ./ $"jam@($target):nixos" | complete)(ssh -qtt $"jam@($target)" ./nixos/rebuild.nu | complete)}def build [cmd: string...args: string]: nothing -> record {let nh = if (which nh | is-not-empty) {[ nh ]} else {print-notify "Command 'nh' not found, falling back to 'nix run nixpkgs#nh'."[ nix run nixpkgs#nh -- ]}print-notify $"Rebuilding (sys host | get hostname)."sudo ...$nh $cmd ...$args | complete}# nu-lint-ignore: max_function_body_lengthdef start-progress-bar []: nothing -> int { # nu-lint-ignore: print_and_return_datajob spawn {sleep 100ms # Give time to spawn before starting animation.const WIDTH = 10mut s = 1.0mut m = 0mut pos = 0mut dir = 1while $env.REBUILD_IN_PROGRESS {$s += 0.1$pos += $dirif $pos >= $WIDTH or $pos <= 0 { $dir *= -1 }let l = ('' | fill --width $pos --character ' ')let r = ('' | fill --width ($WIDTH - $pos) --character ' ')if $s == 60.0 { $m += 1 }let s = $s | into intlet msg = $"(ansi p)($l)█($r)(ansi rst) Elapsed: ($s)s\r"print --no-newline $msgjob send 0sleep 100ms}}}def --wrapped main [ # nu-lint-ignore: max_function_body_length--remote: string = "" # Build a remote host--all # Attempt to rebuild all hosts...rest: string # Extra arguments to pass to nh]: nothing -> nothing {let os = uname | get kernel-name | str downcaselet config = if $os == darwin {{path: /Users/jam/nixos, cmd: $os}} else {{path: /home/jam/nixos, cmd: os}}let hostname = sys host | get hostnamelet remote = $remote | str trim | str downcaselet is_remote = $remote | is-not-emptyconst HOSTS = [blackwelldatekiwilimepearplumsloeyuzu]let target = if $is_remote {if $remote == $hostname {print-notify "Error: Attempting to build the current systems configuration as a remote system."exit 1}$remote} else { $hostname }let nix_args = [----fallback]let nh_args = [switch$config.path--accept-flake-config--bypass-root-check...$nix_args...$rest]if $all {print-notify $"Rebuilding all hosts in parallel: ($HOSTS)."print-notify "Results will be collected and shown upon completion."print-notify "This will take some time."$env.REBUILD_IN_PROGRESS = truestart-progress-barlet results = $HOSTS | par-each --keep-order {|h|let remote = $h != $hostnameif $is_remote {let result = remote-build --quiet $h{host: $h, success: ($result.exit_code == 0), stderr: $result.stderr}} else {let result = build $config.cmd ...$nh_args{host: $h, success: ($result.exit_code == 0), stderr: $result.stderr}}}$env.REBUILD_IN_PROGRESS = falseprint-notify "All builds complete."for r in $results {if $r.success {print-notify $"✓ ($r.host)"} else {print-notify $"✗ ($r.host) failed"if $r.stderr != null {print-notify $" stderr: ($r.stderr)"}}}return}$env.REBUILD_IN_PROGRESS = truestart-progress-barlet result = if $is_remote {remote-build $target} else {build $config.cmd ...$nh_args}$env.REBUILD_IN_PROGRESS = falsematch $result.exit_code {0 => { print-notify $"Rebuild for ($target) succeeded." }_ => {print-notify $"Rebuild for ($target) failed."print-notify $"Error: ($result)"}}}