Skip to content

Commit

Permalink
nixos-rebuild: Avoid empty command
Browse files Browse the repository at this point in the history
"${a[@]}" => ok
"${foo:+a[@]}" => empty string when length is 0
  • Loading branch information
roberth committed Jan 14, 2024
1 parent 472dfb3 commit c8c3c58
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
local c
if [[ "${useSudo:-x}" = 1 ]]; then
c=("${sudoCommand[@]}")
else
c=()
fi

if [ -z "$targetHost" ]; then
runCmd "${useSudo:+${sudoCommand[@]}}" "$@"
runCmd "${c[@]}" "$@"
else
runCmd ssh $SSHOPTS "$targetHost" "${useSudo:+${sudoCommand[@]}}" "$@"
runCmd ssh $SSHOPTS "$targetHost" "${c[@]}" "$@"
fi
}

Expand Down

0 comments on commit c8c3c58

Please sign in to comment.