Preserve PATH variable when using sudo

Some systems set `secure_path` in sudoers. When this is set
the `PATH` variable is not set in the sudo environment. Using
`--preserve-env=PATH` ensures that the PATH env var is set properly
in those systems.

This is similar to the issue with [darwin-rebuild](https://github.com/nix-darwin/nix-darwin/issues/798)
not working with sudo on these systems.
This commit is contained in:
Brian Romanko 2025-05-27 16:33:25 -07:00
parent 72c88d5928
commit 300af6fcc5
No known key found for this signature in database

View file

@ -802,6 +802,7 @@ in
if [ -f "${cfg.brewPrefix}/brew" ]; then
PATH="${cfg.brewPrefix}:${lib.makeBinPath [ pkgs.mas ]}:$PATH" \
sudo \
--preserve-env=PATH \
--user=${escapeShellArg cfg.user} \
--set-home \
${cfg.onActivation.brewBundleCmd}