mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
Merge pull request #11761 from abitrolly/alt-sudo
install: Allow to specify alternative `sudo` command
This commit is contained in:
commit
9cf1b0cb57
2 changed files with 13 additions and 7 deletions
|
@ -56,6 +56,9 @@ readonly NIX_INSTALLED_CACERT="@cacert@"
|
||||||
#readonly NIX_INSTALLED_CACERT="/nix/store/7dxhzymvy330i28ii676fl1pqwcahv2f-nss-cacert-3.49.2"
|
#readonly NIX_INSTALLED_CACERT="/nix/store/7dxhzymvy330i28ii676fl1pqwcahv2f-nss-cacert-3.49.2"
|
||||||
readonly EXTRACTED_NIX_PATH="$(dirname "$0")"
|
readonly EXTRACTED_NIX_PATH="$(dirname "$0")"
|
||||||
|
|
||||||
|
# allow to override identity change command
|
||||||
|
readonly NIX_BECOME=${NIX_BECOME:-sudo}
|
||||||
|
|
||||||
readonly ROOT_HOME=~root
|
readonly ROOT_HOME=~root
|
||||||
|
|
||||||
if [ -t 0 ] && [ -z "${NIX_INSTALLER_YES:-}" ]; then
|
if [ -t 0 ] && [ -z "${NIX_INSTALLER_YES:-}" ]; then
|
||||||
|
@ -123,7 +126,7 @@ uninstall_directions() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
$step. Restore $profile_target$PROFILE_BACKUP_SUFFIX back to $profile_target
|
$step. Restore $profile_target$PROFILE_BACKUP_SUFFIX back to $profile_target
|
||||||
|
|
||||||
sudo mv $profile_target$PROFILE_BACKUP_SUFFIX $profile_target
|
$NIX_BECOME mv $profile_target$PROFILE_BACKUP_SUFFIX $profile_target
|
||||||
|
|
||||||
(after this one, you may need to re-open any terminals that were
|
(after this one, you may need to re-open any terminals that were
|
||||||
opened while it existed.)
|
opened while it existed.)
|
||||||
|
@ -136,7 +139,7 @@ EOF
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
$step. Delete the files Nix added to your system:
|
$step. Delete the files Nix added to your system:
|
||||||
|
|
||||||
sudo rm -rf "/etc/nix" "$NIX_ROOT" "$ROOT_HOME/.nix-profile" "$ROOT_HOME/.nix-defexpr" "$ROOT_HOME/.nix-channels" "$ROOT_HOME/.local/state/nix" "$ROOT_HOME/.cache/nix" "$HOME/.nix-profile" "$HOME/.nix-defexpr" "$HOME/.nix-channels" "$HOME/.local/state/nix" "$HOME/.cache/nix"
|
$NIX_BECOME rm -rf "/etc/nix" "$NIX_ROOT" "$ROOT_HOME/.nix-profile" "$ROOT_HOME/.nix-defexpr" "$ROOT_HOME/.nix-channels" "$ROOT_HOME/.local/state/nix" "$ROOT_HOME/.cache/nix" "$HOME/.nix-profile" "$HOME/.nix-defexpr" "$HOME/.nix-channels" "$HOME/.local/state/nix" "$HOME/.cache/nix"
|
||||||
|
|
||||||
and that is it.
|
and that is it.
|
||||||
|
|
||||||
|
@ -343,7 +346,7 @@ __sudo() {
|
||||||
|
|
||||||
echo "I am executing:"
|
echo "I am executing:"
|
||||||
echo ""
|
echo ""
|
||||||
printf " $ sudo %s\\n" "$cmd"
|
printf " $ $NIX_BECOME %s\\n" "$cmd"
|
||||||
echo ""
|
echo ""
|
||||||
echo "$expl"
|
echo "$expl"
|
||||||
echo ""
|
echo ""
|
||||||
|
@ -361,7 +364,9 @@ _sudo() {
|
||||||
if is_root; then
|
if is_root; then
|
||||||
env "$@"
|
env "$@"
|
||||||
else
|
else
|
||||||
sudo "$@"
|
# env sets environment variables for sudo alternatives
|
||||||
|
# that don't support "VAR=value command" syntax
|
||||||
|
$NIX_BECOME env "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ self="$(dirname "$0")"
|
||||||
nix="@nix@"
|
nix="@nix@"
|
||||||
cacert="@cacert@"
|
cacert="@cacert@"
|
||||||
|
|
||||||
|
# allow to override identity change command
|
||||||
|
readonly NIX_BECOME="${NIX_BECOME:-sudo}"
|
||||||
|
|
||||||
if ! [ -e "$self/.reginfo" ]; then
|
if ! [ -e "$self/.reginfo" ]; then
|
||||||
echo "$0: incomplete installer (.reginfo is missing)" >&2
|
echo "$0: incomplete installer (.reginfo is missing)" >&2
|
||||||
|
@ -63,7 +65,6 @@ while [ $# -gt 0 ]; do
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
INSTALL_MODE=no-daemon
|
INSTALL_MODE=no-daemon
|
||||||
# intentional tail space
|
|
||||||
ACTION=install
|
ACTION=install
|
||||||
;;
|
;;
|
||||||
--yes)
|
--yes)
|
||||||
|
@ -135,8 +136,8 @@ echo "performing a single-user installation of Nix..." >&2
|
||||||
|
|
||||||
if ! [ -e "$dest" ]; then
|
if ! [ -e "$dest" ]; then
|
||||||
cmd="mkdir -m 0755 $dest && chown $USER $dest"
|
cmd="mkdir -m 0755 $dest && chown $USER $dest"
|
||||||
echo "directory $dest does not exist; creating it by running '$cmd' using sudo" >&2
|
echo "directory $dest does not exist; creating it by running '$cmd' using $NIX_BECOME" >&2
|
||||||
if ! sudo sh -c "$cmd"; then
|
if ! $NIX_BECOME sh -c "$cmd"; then
|
||||||
echo "$0: please manually run '$cmd' as root to create $dest" >&2
|
echo "$0: please manually run '$cmd' as root to create $dest" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue