Skip to content

Commit

Permalink
Merge pull request #831 from rkitover/high-sierra-fix
Browse files Browse the repository at this point in the history
darwin-rebuild: fix sudo invocation on High Sierra
  • Loading branch information
Enzime authored Dec 22, 2023
2 parents 4b9b83d + f81fbc2 commit 010a625
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkgs/nix-tools/darwin-rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ showSyntax() {
exit 1
}

sudo() {
if command sudo --help | grep -- --preserve-env= >/dev/null; then
command sudo -H --preserve-env=PATH env "$@"
else
command sudo -H "$@"
fi
}

# Parse the command line.
origArgs=("$@")
extraMetadataFlags=()
Expand Down Expand Up @@ -187,7 +195,7 @@ fi

if [ "$action" = list ] || [ "$action" = rollback ]; then
if [ "$USER" != root ] && [ ! -w $(dirname "$profile") ]; then
sudo -H --preserve-env=PATH env nix-env -p "$profile" "${extraProfileFlags[@]}"
sudo nix-env -p "$profile" "${extraProfileFlags[@]}"
else
nix-env -p "$profile" "${extraProfileFlags[@]}"
fi
Expand All @@ -205,7 +213,7 @@ if [ -z "$systemConfig" ]; then exit 0; fi

if [ "$action" = switch ]; then
if [ "$USER" != root ] && [ ! -w $(dirname "$profile") ]; then
sudo -H --preserve-env=PATH env nix-env -p "$profile" --set "$systemConfig"
sudo nix-env -p "$profile" --set "$systemConfig"
else
nix-env -p "$profile" --set "$systemConfig"
fi
Expand All @@ -215,7 +223,7 @@ if [ "$action" = switch ] || [ "$action" = activate ] || [ "$action" = rollback
"$systemConfig/activate-user"

if [ "$USER" != root ]; then
sudo -H --preserve-env=PATH "$systemConfig/activate"
sudo "$systemConfig/activate"
else
"$systemConfig/activate"
fi
Expand Down

0 comments on commit 010a625

Please sign in to comment.