From 94eb132962493dc17afc1d18e31cac1fe439acfe Mon Sep 17 00:00:00 2001 From: alexion Date: Wed, 21 Oct 2026 17:03:42 -0400 Subject: [PATCH] fix(shell): reuse sudo session during deployment --- .../shell/fish/functions/deploy-to.fish | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/configs/nixos/modules/shell/fish/functions/deploy-to.fish b/configs/nixos/modules/shell/fish/functions/deploy-to.fish index 525717c..6b35a7d 100644 --- a/configs/nixos/modules/shell/fish/functions/deploy-to.fish +++ b/configs/nixos/modules/shell/fish/functions/deploy-to.fish @@ -47,6 +47,8 @@ or begin return $status end +set remote_nar + if test (count $missing_paths) -gt 0 set nar_file (mktemp --suffix=.nar) or return $status @@ -70,26 +72,23 @@ if test (count $missing_paths) -gt 0 return $scp_status end - echo "deploy-to: importing closure on $host" >&2 - ssh -t $host "sudo sh -c 'nix-store --import < $remote_nar' && rm -f $remote_nar" - or begin - echo "deploy-to: closure import failed for $host" >&2 - return $status - end + echo "deploy-to: importing the closure, recording $system_path, and activating it on $host" >&2 else echo "deploy-to: $host already has the full closure for $system_path" >&2 + echo "deploy-to: recording $system_path and activating it on $host" >&2 end -echo "deploy-to: recording $system_path as the system profile on $host" >&2 -ssh -t $host sudo nix-env --profile /nix/var/nix/profiles/system --set $system_path -or begin - echo "deploy-to: system profile update failed for $host" >&2 - return $status -end +set remote_script ( + string join '; ' \ + 'system_path=$1' \ + 'remote_nar=$2' \ + 'if test -n "$remote_nar"; then nix-store --import < "$remote_nar"; rm -f "$remote_nar"; fi' \ + 'nix-env --profile /nix/var/nix/profiles/system --set "$system_path"' \ + '"$system_path/bin/switch-to-configuration" switch' +) -echo "deploy-to: activating $system_path on $host" >&2 -ssh -t $host sudo "$system_path/bin/switch-to-configuration" switch +ssh -t $host sudo sh -e -c (string escape -- $remote_script) sh (string escape -- $system_path $remote_nar) or begin - echo "deploy-to: activation failed for $host" >&2 + echo "deploy-to: deployment failed for $host" >&2 return $status end