From 99bebcbfa4df466c05b9114510eb6d9124ef59ca Mon Sep 17 00:00:00 2001 From: K900 Date: Sun, 18 Feb 2024 10:24:51 +0300 Subject: nixos-rebuild: avoid --preserve-env sudo-rs does not support it, but also it's just spooky action at a distance. --- pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh index 2051368a49f6..1868f6b2af1b 100755 --- a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh +++ b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh @@ -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." -- cgit 1.4.1