fix(shell): reuse sudo session during deployment

This commit was merged in pull request #206.
This commit is contained in:
2026-10-21 17:03:42 -04:00
parent 8e01e1621b
commit 94eb132962

View File

@@ -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