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).
This commit is contained in:
Bjørn Forsman 2019-10-23 20:22:39 +02:00
parent d7b18bcb37
commit 2c09cfc097
2 changed files with 19 additions and 4 deletions

View file

@ -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>

View file

@ -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