nixos-rebuild: restore local sudo functionality

This functionality used to exist and was then removed in #331741. The
issue was that $SUDO_USER is already used by `sudo` as an environment
variable.

This change makes it possible to checkout a flake repository, as a user,
enter the devshell, and with the additions below and apply changes with
`nixos-rebuild switch`.

```nix
{ pkgs }:
let
nixos-rebuild = pkgs.writeShellApplication {
name = "nixos-rebuild";
runtimeInputs = [ pkgs.nixos-rebuild ];
text = ''
set -euo pipefail
exec nixos-rebuild --flake "$PRJ_ROOT" --use-local-sudo "$@"
'';
};
in
pkgs.mkShellNoCC {
packages = [
nixos-rebuild
];

shellHook = ''
export PRJ_ROOT=$PWD
'';
}
```

zimbatm 7d8a9fa0 d022a1e7

Changed files
+5 -1
pkgs
os-specific
linux
nixos-rebuild
+5 -1
pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
···
buildHost=
targetHost=
remoteSudo=
+
localSudo=
noSSHTTY=
verboseScript=
noFlake=
···
--use-remote-sudo)
remoteSudo=1
;;
+
--use-local-sudo)
+
localSudo=1
+
;;
--no-ssh-tty)
noSSHTTY=1
;;
···
t="-t"
fi
-
if [ -n "$remoteSudo" ]; then
+
if [[ -n "$remoteSudo" || -n "$localSudo" ]]; then
useSudo=1 SSHOPTS="$SSHOPTS $t" targetHostCmd "$@"
else
# While a tty might not be necessary, we apply it to be consistent with