1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-31 04:04:45 +00:00
This commit is contained in:
Kabir Oberai 2025-03-29 00:36:48 -04:00 committed by GitHub
commit 0ac1457a09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,11 +22,11 @@ showSyntax() {
exit 1 exit 1
} }
sudo() { # We use `env` before our command to ensure the preserved PATH gets checked
# We use `env` before our command to ensure the preserved PATH gets checked # when trying to resolve the command to execute
# when trying to resolve the command to execute sudo_base="command sudo -H --preserve-env=PATH --preserve-env=SSH_CONNECTION"
command sudo -H --preserve-env=PATH --preserve-env=SSH_CONNECTION env "$@" sudo="$sudo_base env"
} sudo() { $sudo "$@"; }
# Parse the command line. # Parse the command line.
origArgs=("$@") origArgs=("$@")
@ -219,11 +219,16 @@ if [ "$action" = switch ]; then
fi fi
if [ "$action" = switch ] || [ "$action" = activate ] || [ "$action" = rollback ]; then if [ "$action" = switch ] || [ "$action" = activate ] || [ "$action" = rollback ]; then
"$systemConfig/activate-user"
if [ "$USER" != root ]; then if [ "$USER" != root ]; then
sudo "$systemConfig/activate" # Running `$systemConfig/activate-user` may cause subsequent sudo invocations to prompt
# for the password even if we previously ran sudo in the same session, since `brew` resets
# the sudo timestamp: see https://github.com/Homebrew/brew/pull/17694.
# Indeed, by this point we've already run `nix-env --set` as sudo. So to avoid prompting a
# second time, we become root *before* running activate-user and then drop down to the user
# to invoke it. This way, the call to `activate` doesn't require a password.
sudo @shell@ -c "$sudo_base -u $USER $systemConfig/activate-user && $systemConfig/activate"
else else
"$systemConfig/activate-user"
"$systemConfig/activate" "$systemConfig/activate"
fi fi
fi fi