From 4734959784c8f12ce0bf9d33bf7a18be07c97d2a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 25 Sep 2024 11:07:08 +0200 Subject: [PATCH] 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. --- pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh index 1ab5c8346f33..dc5ed4b2d02c 100755 --- a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh +++ b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh @@ -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 }