diff options
author | Bjørn Forsman <bjorn.forsman@gmail.com> | 2019-10-14 21:14:35 +0200 |
---|---|---|
committer | Bjørn Forsman <bjorn.forsman@gmail.com> | 2019-10-22 20:44:25 +0200 |
commit | 263a81e285faacb968d11f58e0dba2bb75a92a45 (patch) | |
tree | 5714c5891d5b5ae9540610e039d2fe3b5d076354 /nixos | |
parent | 14803d80703548aae78deb53037156ee3da15166 (diff) | |
download | nixlib-263a81e285faacb968d11f58e0dba2bb75a92a45.tar nixlib-263a81e285faacb968d11f58e0dba2bb75a92a45.tar.gz nixlib-263a81e285faacb968d11f58e0dba2bb75a92a45.tar.bz2 nixlib-263a81e285faacb968d11f58e0dba2bb75a92a45.tar.lz nixlib-263a81e285faacb968d11f58e0dba2bb75a92a45.tar.xz nixlib-263a81e285faacb968d11f58e0dba2bb75a92a45.tar.zst nixlib-263a81e285faacb968d11f58e0dba2bb75a92a45.zip |
nixos-rebuild: support sudo + --target-host
This adds support for deploying to remote hosts without being root: sudo nixos-rebuild --target-host non-root@host Without this change, only root@host is able to deploy. The idea is that if the local command is run with sudo, so should the remote one, thus there is no need for adding any CLI options.
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/installer/tools/nixos-rebuild.sh | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index ea434ca87416..891f374df536 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -22,6 +22,7 @@ repair= profile=/nix/var/nix/profiles/system buildHost= targetHost= +maybeSudo= while [ "$#" -gt 0 ]; do i="$1"; shift 1 @@ -96,6 +97,9 @@ while [ "$#" -gt 0 ]; do esac done +if [ -n "$SUDO_USER" ]; then + maybeSudo="sudo " +fi if [ -z "$buildHost" -a -n "$targetHost" ]; then buildHost="$targetHost" @@ -111,9 +115,9 @@ buildHostCmd() { if [ -z "$buildHost" ]; then "$@" elif [ -n "$remoteNix" ]; then - ssh $SSHOPTS "$buildHost" env PATH="$remoteNix:$PATH" "$@" + ssh $SSHOPTS "$buildHost" env PATH="$remoteNix:$PATH" "$maybeSudo$@" else - ssh $SSHOPTS "$buildHost" "$@" + ssh $SSHOPTS "$buildHost" "$maybeSudo$@" fi } @@ -121,7 +125,7 @@ targetHostCmd() { if [ -z "$targetHost" ]; then "$@" else - ssh $SSHOPTS "$targetHost" "$@" + ssh $SSHOPTS "$targetHost" "$maybeSudo$@" fi } |