Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 93204f1d8a95
Choose a base ref
...
head repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ab10bac1b177
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Jan 21, 2020

  1. nixos-rebuild: fix the maybeSudo usage

    * properly expand the command using arrays instead of strings
    * also handle sudo on the localhost
    zimbatm committed Jan 21, 2020
    8

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Ma27 Maximilian Bosch
    Copy the full SHA
    ab10bac View commit details
Showing with 10 additions and 6 deletions.
  1. +10 −6 nixos/modules/installer/tools/nixos-rebuild.sh
16 changes: 10 additions & 6 deletions nixos/modules/installer/tools/nixos-rebuild.sh
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ repair=
profile=/nix/var/nix/profiles/system
buildHost=
targetHost=
maybeSudo=
maybeSudo=()

while [ "$#" -gt 0 ]; do
i="$1"; shift 1
@@ -92,7 +92,7 @@ while [ "$#" -gt 0 ]; do
;;
--use-remote-sudo)
# note the trailing space
maybeSudo="sudo "
maybeSudo=(sudo --)
shift 1
;;
*)
@@ -102,6 +102,10 @@ while [ "$#" -gt 0 ]; do
esac
done

if [ -n "$SUDO_USER" ]; then
maybeSudo=(sudo --)
fi

if [ -z "$buildHost" -a -n "$targetHost" ]; then
buildHost="$targetHost"
fi
@@ -116,17 +120,17 @@ buildHostCmd() {
if [ -z "$buildHost" ]; then
"$@"
elif [ -n "$remoteNix" ]; then
ssh $SSHOPTS "$buildHost" env PATH="$remoteNix:$PATH" "$maybeSudo$@"
ssh $SSHOPTS "$buildHost" env PATH="$remoteNix:$PATH" "${maybeSudo[@]}" "$@"
else
ssh $SSHOPTS "$buildHost" "$maybeSudo$@"
ssh $SSHOPTS "$buildHost" "${maybeSudo[@]}" "$@"
fi
}

targetHostCmd() {
if [ -z "$targetHost" ]; then
"$@"
"${maybeSudo[@]}" "$@"
else
ssh $SSHOPTS "$targetHost" "$maybeSudo$@"
ssh $SSHOPTS "$targetHost" "${maybeSudo[@]}" "$@"
fi
}