about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaciej Krüger <mkg20001@gmail.com>2024-02-26 14:32:00 +0100
committerGitHub <noreply@github.com>2024-02-26 14:32:00 +0100
commit94cda73bf2fd675de987db7c3ac81e861b892266 (patch)
treea9a2926736e666a60008ebdfc7aee60cb222f17e
parentf0ad0db81a4769f8b7b819d2a66a3989e5526a5e (diff)
parent99bebcbfa4df466c05b9114510eb6d9124ef59ca (diff)
downloadnixlib-94cda73bf2fd675de987db7c3ac81e861b892266.tar
nixlib-94cda73bf2fd675de987db7c3ac81e861b892266.tar.gz
nixlib-94cda73bf2fd675de987db7c3ac81e861b892266.tar.bz2
nixlib-94cda73bf2fd675de987db7c3ac81e861b892266.tar.lz
nixlib-94cda73bf2fd675de987db7c3ac81e861b892266.tar.xz
nixlib-94cda73bf2fd675de987db7c3ac81e861b892266.tar.zst
nixlib-94cda73bf2fd675de987db7c3ac81e861b892266.zip
Merge pull request #289680 from K900/nixos-rebuild-preserve-env
nixos-rebuild: avoid --preserve-env
-rwxr-xr-xpkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh19
1 files 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."