about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBjørn Forsman <bjorn.forsman@gmail.com>2019-10-23 20:22:39 +0200
committerBjørn Forsman <bjorn.forsman@gmail.com>2019-11-07 17:03:12 +0100
commit2c09cfc097daef5b85d21fe906441b5702bb2101 (patch)
tree2223d4f3e34601cbd6031460d24ba898676d8b56
parentd7b18bcb3718c87767619e117e363e830c81913f (diff)
downloadnixlib-2c09cfc097daef5b85d21fe906441b5702bb2101.tar
nixlib-2c09cfc097daef5b85d21fe906441b5702bb2101.tar.gz
nixlib-2c09cfc097daef5b85d21fe906441b5702bb2101.tar.bz2
nixlib-2c09cfc097daef5b85d21fe906441b5702bb2101.tar.lz
nixlib-2c09cfc097daef5b85d21fe906441b5702bb2101.tar.xz
nixlib-2c09cfc097daef5b85d21fe906441b5702bb2101.tar.zst
nixlib-2c09cfc097daef5b85d21fe906441b5702bb2101.zip
nixos-rebuild: add explicit option to enable (remote) sudo
Add --use-remote-sudo option. When set, remote commands will be prefixed
with 'sudo'. This allows using sudo remotely _without_ having to use
sudo locally (when using --build-host/--taget-host).
-rw-r--r--nixos/doc/manual/man-nixos-rebuild.xml14
-rw-r--r--nixos/modules/installer/tools/nixos-rebuild.sh9
2 files changed, 19 insertions, 4 deletions
diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml
index c697b7ee0472..495dbc8859b1 100644
--- a/nixos/doc/manual/man-nixos-rebuild.xml
+++ b/nixos/doc/manual/man-nixos-rebuild.xml
@@ -494,6 +494,20 @@
      </para>
     </listitem>
    </varlistentry>
+
+   <varlistentry>
+    <term>
+     <option>--use-remote-sudo</option>
+    </term>
+    <listitem>
+     <para>
+      When set, nixos-rebuild prefixes remote commands that run on
+      the <option>--build-host</option> and <option>--target-host</option>
+      systems with <command>sudo</command>. Setting this option allows
+      deploying as a non-root user.
+     </para>
+    </listitem>
+   </varlistentry>
   </variablelist>
 
   <para>
diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh
index 891f374df536..c53dc1000c4a 100644
--- a/nixos/modules/installer/tools/nixos-rebuild.sh
+++ b/nixos/modules/installer/tools/nixos-rebuild.sh
@@ -90,6 +90,11 @@ while [ "$#" -gt 0 ]; do
         targetHost="$1"
         shift 1
         ;;
+      --use-remote-sudo)
+        # note the trailing space
+        maybeSudo="sudo "
+        shift 1
+        ;;
       *)
         echo "$0: unknown option \`$i'"
         exit 1
@@ -97,10 +102,6 @@ while [ "$#" -gt 0 ]; do
     esac
 done
 
-if [ -n "$SUDO_USER" ]; then
-    maybeSudo="sudo "
-fi
-
 if [ -z "$buildHost" -a -n "$targetHost" ]; then
     buildHost="$targetHost"
 fi