nixos-rebuild: Add proper escaping to ssh calls

SSH merges its arguments by space-concatenation - it does not preserve
the array structure.

This is arguably a historic mistake, whose fix would be too breaking.
I suppose it will stay this way forever, until perhaps a better behavior
can be opted in to using a flag, and I don't think this flag exists yet.

To make multi-argument commands work reliably over ssh, we need to escape
them, which is what the ${@@Q} incantation achieves.
This commit is contained in:
Robert Hensing
2024-10-30 00:21:20 +01:00
parent 6427500989
commit 4734959784
@@ -220,9 +220,9 @@ buildHostCmd() {
if [ -z "$buildHost" ]; then
runCmd "$@"
elif [ -n "$remoteNix" ]; then
runCmd ssh $SSHOPTS "$buildHost" "${c[@]}" env PATH="$remoteNix":'$PATH' "$@"
runCmd ssh $SSHOPTS "$buildHost" "${c[@]}" env PATH="$remoteNix":'$PATH' "${@@Q}"
else
runCmd ssh $SSHOPTS "$buildHost" "${c[@]}" "$@"
runCmd ssh $SSHOPTS "$buildHost" "${c[@]}" "${@@Q}"
fi
}
@@ -237,7 +237,7 @@ targetHostCmd() {
if [ -z "$targetHost" ]; then
runCmd "${c[@]}" "$@"
else
runCmd ssh $SSHOPTS "$targetHost" "${c[@]}" "$@"
runCmd ssh $SSHOPTS "$targetHost" "${c[@]}" "${@@Q}"
fi
}