From c8c3c5854e16ab98afa718801badd62fff6bbb42 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 14 Jan 2024 02:23:52 +0100 Subject: [PATCH] nixos-rebuild: Avoid empty command "${a[@]}" => ok "${foo:+a[@]}" => empty string when length is 0 --- .../linux/nixos-rebuild/nixos-rebuild.sh | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh index 1b7ec45ae2d3..006b5db6320c 100755 --- a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh +++ b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh @@ -177,20 +177,34 @@ runCmd() { } buildHostCmd() { + local c + if [[ "${useSudo:-x}" = 1 ]]; then + c=("${sudoCommand[@]}") + else + c=() + fi + if [ -z "$buildHost" ]; then runCmd "$@" elif [ -n "$remoteNix" ]; then - runCmd ssh $SSHOPTS "$buildHost" "${useSudo:+${sudoCommand[@]}}" env PATH="$remoteNix":'$PATH' "$@" + runCmd ssh $SSHOPTS "$buildHost" "${c[@]}" env PATH="$remoteNix":'$PATH' "$@" else - runCmd ssh $SSHOPTS "$buildHost" "${useSudo:+${sudoCommand[@]}}" "$@" + runCmd ssh $SSHOPTS "$buildHost" "${c[@]}" "$@" fi } targetHostCmd() { - if [ -z "$targetHost" ]; then - runCmd "${useSudo:+${sudoCommand[@]}}" "$@" + local c + if [[ "${useSudo:-x}" = 1 ]]; then + c=("${sudoCommand[@]}") else - runCmd ssh $SSHOPTS "$targetHost" "${useSudo:+${sudoCommand[@]}}" "$@" + c=() + fi + + if [ -z "$targetHost" ]; then + runCmd "${c[@]}" "$@" + else + runCmd ssh $SSHOPTS "$targetHost" "${c[@]}" "$@" fi }