diff --git a/deploy.nu b/deploy.nu index 329fd55..ff40ff9 100755 --- a/deploy.nu +++ b/deploy.nu @@ -59,6 +59,7 @@ let hosts = { type: "nixos", user: "root", addr: "159.195.58.28", + port: 2200, }, pupos: { type: "nixos", @@ -71,6 +72,8 @@ def deploy [hostname: string, boot: bool, target_build: bool] { log info $"start deploy host ($hostname)" let hooktitle = $"/($hostname)/deploy" let hostcfg = $hosts | get $hostname + let port = ($hostcfg | get -o port | default 22) + let ssh_opts = ["-p" ($port | into string)] let target = $"($hostcfg.user)@($hostcfg.addr)" let remote_source = $"/tmp/ark-deploy-($hostname)" @@ -80,7 +83,7 @@ def deploy [hostname: string, boot: bool, target_build: bool] { webhook $"($hooktitle)/($action)" $"=== ($action) ($hostname) started ===" let start = date now do $block - let exit_code = $env.LAST_EXIT_CODE + let exit_code = ($env | get -o LAST_EXIT_CODE | default 0) let elapsed = (date now) - $start let failed = $exit_code != 0 webhook $"($hooktitle)/($action)" $"=== ($action) ($hostname) is done ===\n\ntook ($elapsed)" $exit_code $failed @@ -91,8 +94,8 @@ def deploy [hostname: string, boot: bool, target_build: bool] { let result_file = (^mktemp) let build_cmd = if $target_build { { - rsync -a --delete --exclude .git --exclude .direnv --exclude "result*" $"($env.NH_FLAKE)/" $"($target):($remote_source)/" - ^ssh $target $"cd ($remote_source) && nix build --accept-flake-config --no-link --print-out-paths '.#nixosConfigurations.($hostname).config.system.build.toplevel'" + rsync -a --delete -e $"ssh ($ssh_opts | str join ' ')" --exclude .git --exclude .direnv --exclude "result*" $"($env.NH_FLAKE)/" $"($target):($remote_source)/" + ^ssh ...($ssh_opts | append [$target]) $"cd ($remote_source) && nix build --accept-flake-config --no-link --print-out-paths '.#nixosConfigurations.($hostname).config.system.build.toplevel'" | str trim | save -f $result_file } @@ -110,7 +113,7 @@ def deploy [hostname: string, boot: bool, target_build: bool] { let result_link = if $target_build { open $result_file | str trim } else { ^readlink $result_dir } if $target_build == false { - let copy_cmd = {nix copy --no-check-sigs -s --to $"ssh://($target)" $result_link} + let copy_cmd = {with-env { NIX_SSHOPTS: ($ssh_opts | str join " ") } { nix copy --no-check-sigs -s --to $"ssh://($target)" $result_link }} if (run_step "copy to" $copy_cmd) { return } @@ -122,13 +125,13 @@ def deploy [hostname: string, boot: bool, target_build: bool] { "nixos" => $"sudo nix-env -p /nix/var/nix/profiles/system --set '($result_link)' && sudo '($result_link)/bin/switch-to-configuration' '($action)'", "home" => $"($result_link)/activate", } - ssh $target $cmd + ssh ...($ssh_opts | append [$target]) $cmd if $boot { log info "rebooting target..." - ssh $target "sudo reboot" + ssh ...($ssh_opts | append [$target]) "sudo reboot" } if $target_build { - ssh $target $"rm -rf '($remote_source)'" + ssh ...($ssh_opts | append [$target]) $"rm -rf '($remote_source)'" } } if (run_step "activate" $activate_cmd) {