From f9949039dae7248afabec7d86b7d5c5633eb9edc Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Sun, 17 Dec 2023 05:16:22 -0800 Subject: [PATCH] darwin-rebuild: fix sudo invocation on High Sierra The version of sudo on macOS 10.13 High Sierra does not support the `--preserve-env=LIST` option syntax. Override sudo with a shell function that checks for the availability of this option syntax, and set PATH for the command being invoked with `sh -c` otherwise. Signed-off-by: Rafael Kitover --- pkgs/nix-tools/darwin-rebuild.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkgs/nix-tools/darwin-rebuild.sh b/pkgs/nix-tools/darwin-rebuild.sh index 47c2e3120..5edde8a4b 100644 --- a/pkgs/nix-tools/darwin-rebuild.sh +++ b/pkgs/nix-tools/darwin-rebuild.sh @@ -16,6 +16,14 @@ showSyntax() { exit 1 } +sudo() { + if command sudo --help | grep -- --preserve-env= >/dev/null; then + command sudo -H --preserve-env=PATH "$@" + else + command sudo -H -- sh -c 'PATH='"'$PATH'"' "$@"' -- "$@" + fi +} + # Parse the command line. origArgs=("$@") extraMetadataFlags=() @@ -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 env nix-env -p "$profile" "${extraProfileFlags[@]}" else nix-env -p "$profile" "${extraProfileFlags[@]}" fi @@ -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 env nix-env -p "$profile" --set "$systemConfig" else nix-env -p "$profile" --set "$systemConfig" fi @@ -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