fix(shell): reuse sudo session during deployment #206

Merged
alexion merged 1 commits from fix/deploy-to-sudo-prompt into main 2026-10-21 18:01:42 -04:00

View File

@@ -47,6 +47,8 @@ or begin
return $status return $status
end end
set remote_nar
if test (count $missing_paths) -gt 0 if test (count $missing_paths) -gt 0
set nar_file (mktemp --suffix=.nar) set nar_file (mktemp --suffix=.nar)
or return $status or return $status
@@ -70,26 +72,23 @@ if test (count $missing_paths) -gt 0
return $scp_status return $scp_status
end end
echo "deploy-to: importing closure on $host" >&2 echo "deploy-to: importing the closure, recording $system_path, and activating it 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
else else
echo "deploy-to: $host already has the full closure for $system_path" >&2 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 end
echo "deploy-to: recording $system_path as the system profile on $host" >&2 set remote_script (
ssh -t $host sudo nix-env --profile /nix/var/nix/profiles/system --set $system_path string join '; ' \
or begin 'system_path=$1' \
echo "deploy-to: system profile update failed for $host" >&2 'remote_nar=$2' \
return $status 'if test -n "$remote_nar"; then nix-store --import < "$remote_nar"; rm -f "$remote_nar"; fi' \
end '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 sh -e -c (string escape -- $remote_script) sh (string escape -- $system_path $remote_nar)
ssh -t $host sudo "$system_path/bin/switch-to-configuration" switch
or begin or begin
echo "deploy-to: activation failed for $host" >&2 echo "deploy-to: deployment failed for $host" >&2
return $status return $status
end end