Merge pull request #289680 from K900/nixos-rebuild-preserve-env

nixos-rebuild: avoid --preserve-env
This commit is contained in:
Maciej Krüger 2024-02-26 14:32:00 +01:00 committed by GitHub
commit 94cda73bf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -34,8 +34,7 @@ targetHost=
remoteSudo=
verboseScript=
noFlake=
# comma separated list of vars to preserve when using sudo
preservedSudoVars=NIXOS_INSTALL_BOOTLOADER
installBootloader=
json=
# log the given argument to stderr
@ -57,10 +56,10 @@ while [ "$#" -gt 0 ]; do
;;
--install-grub)
log "$0: --install-grub deprecated, use --install-bootloader instead"
export NIXOS_INSTALL_BOOTLOADER=1
installBootloader=1
;;
--install-bootloader)
export NIXOS_INSTALL_BOOTLOADER=1
installBootloader=1
;;
--no-build-nix)
buildNix=
@ -157,8 +156,6 @@ while [ "$#" -gt 0 ]; do
esac
done
sudoCommand=(sudo --preserve-env="$preservedSudoVars" --)
if [[ -n "$SUDO_USER" ]]; then
useSudo=1
fi
@ -179,7 +176,7 @@ runCmd() {
buildHostCmd() {
local c
if [[ "${useSudo:-x}" = 1 ]]; then
c=("${sudoCommand[@]}")
c=("sudo")
else
c=()
fi
@ -196,7 +193,7 @@ buildHostCmd() {
targetHostCmd() {
local c
if [[ "${useSudo:-x}" = 1 ]]; then
c=("${sudoCommand[@]}")
c=("sudo")
else
c=()
fi
@ -756,7 +753,7 @@ if [[ "$action" = switch || "$action" = boot || "$action" = test || "$action" =
cmd=(
"systemd-run"
"-E" "LOCALE_ARCHIVE" # Will be set to new value early in switch-to-configuration script, but interpreter starts out with old value
"-E" "NIXOS_INSTALL_BOOTLOADER"
"-E" "NIXOS_INSTALL_BOOTLOADER=$installBootloader"
"--collect"
"--no-ask-password"
"--pty"
@ -774,14 +771,14 @@ if [[ "$action" = switch || "$action" = boot || "$action" = test || "$action" =
# may be dangerous in remote access (e.g. SSH).
if [[ -n "$NIXOS_SWITCH_USE_DIRTY_ENV" ]]; then
log "warning: skipping systemd-run since NIXOS_SWITCH_USE_DIRTY_ENV is set. This environment variable will be ignored in the future"
cmd=()
cmd=("env" "NIXOS_INSTALL_BOOTLOADER=$installBootloader")
elif ! targetHostSudoCmd "${cmd[@]}" true; then
logVerbose "Skipping systemd-run to switch configuration since it is not working in target host."
cmd=(
"env"
"-i"
"LOCALE_ARCHIVE=$LOCALE_ARCHIVE"
"NIXOS_INSTALL_BOOTLOADER=$NIXOS_INSTALL_BOOTLOADER"
"NIXOS_INSTALL_BOOTLOADER=$installBootloader"
)
else
logVerbose "Using systemd-run to switch configuration."