nixos-rebuild: fix --install-bootloader

nixos-rebuild relies on setting an environment variable to change
behaviour during nixos-rebuild boot/switch between calling update or
install via systemd bootctl. Adding sudo -- as a prefix to various exec
calls does not preserve the environment breaking this mechanism.

This is a some what ugly fix that works.

Closes https://github.com/NixOS/nixpkgs/pull/144429
This commit is contained in:
Anund 2021-11-03 22:37:39 +11:00 committed by Artturin
parent 19781e6663
commit bc5a610cb7

View File

@ -29,7 +29,9 @@ upgrade_all=
profile=/nix/var/nix/profiles/system
buildHost=localhost
targetHost=
maybeSudo=()
remoteSudo=
# comma separated list of vars to preserve when using sudo
preservedSudoVars=NIXOS_INSTALL_BOOTLOADER
while [ "$#" -gt 0 ]; do
i="$1"; shift 1
@ -100,7 +102,7 @@ while [ "$#" -gt 0 ]; do
shift 1
;;
--use-remote-sudo)
maybeSudo=(sudo --)
remoteSudo=1
;;
--flake)
flake="$1"
@ -126,8 +128,8 @@ while [ "$#" -gt 0 ]; do
esac
done
if [ -n "$SUDO_USER" ]; then
maybeSudo=(sudo --)
if [[ -n "$SUDO_USER" || -n $remoteSudo ]]; then
maybeSudo=(sudo --preserve-env="$preservedSudoVars" --)
fi
if [ -z "$buildHost" -a -n "$targetHost" ]; then