diff options
author | Alyssa Ross <hi@alyssa.is> | 2024-01-20 12:31:50 +0100 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2024-01-20 12:32:25 +0100 |
commit | b7baf40e099b4215181fe7b0c63083b12ef2c7fb (patch) | |
tree | a6efabd31d05b6d0a36624729e80377bbbfb0149 /nixpkgs/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh | |
parent | 710028664e26e85cb831a869b3da9f6993902255 (diff) | |
parent | 0799f514b1cd74878174939df79ac60ca5036673 (diff) | |
download | nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar.gz nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar.bz2 nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar.lz nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar.xz nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar.zst nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.zip |
Merge branch 'nixos-unstable-small' of https://github.com/NixOS/nixpkgs
Conflicts: nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix
Diffstat (limited to 'nixpkgs/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh')
-rwxr-xr-x | nixpkgs/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/nixpkgs/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh b/nixpkgs/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh index f9bda1a64b62..006b5db6320c 100755 --- a/nixpkgs/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh +++ b/nixpkgs/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh @@ -157,8 +157,10 @@ while [ "$#" -gt 0 ]; do esac done -if [[ -n "$SUDO_USER" || -n $remoteSudo ]]; then - maybeSudo=(sudo --preserve-env="$preservedSudoVars" --) +sudoCommand=(sudo --preserve-env="$preservedSudoVars" --) + +if [[ -n "$SUDO_USER" ]]; then + useSudo=1 fi # log the given argument to stderr if verbose mode is on @@ -175,20 +177,44 @@ runCmd() { } buildHostCmd() { + local c + if [[ "${useSudo:-x}" = 1 ]]; then + c=("${sudoCommand[@]}") + else + c=() + fi + if [ -z "$buildHost" ]; then runCmd "$@" elif [ -n "$remoteNix" ]; then - runCmd ssh $SSHOPTS "$buildHost" "${maybeSudo[@]}" env PATH="$remoteNix":'$PATH' "$@" + runCmd ssh $SSHOPTS "$buildHost" "${c[@]}" env PATH="$remoteNix":'$PATH' "$@" else - runCmd ssh $SSHOPTS "$buildHost" "${maybeSudo[@]}" "$@" + runCmd ssh $SSHOPTS "$buildHost" "${c[@]}" "$@" fi } targetHostCmd() { + local c + if [[ "${useSudo:-x}" = 1 ]]; then + c=("${sudoCommand[@]}") + else + c=() + fi + if [ -z "$targetHost" ]; then - runCmd "${maybeSudo[@]}" "$@" + runCmd "${c[@]}" "$@" + else + runCmd ssh $SSHOPTS "$targetHost" "${c[@]}" "$@" + fi +} + +targetHostSudoCmd() { + if [ -n "$remoteSudo" ]; then + useSudo=1 SSHOPTS="$SSHOPTS -t" targetHostCmd "$@" else - runCmd ssh $SSHOPTS "$targetHost" "${maybeSudo[@]}" "$@" + # While a tty might not be necessary, we apply it to be consistent with + # sudo usage, and an experience that is more consistent with local deployment. + SSHOPTS="$SSHOPTS -t" targetHostCmd "$@" fi } @@ -667,7 +693,7 @@ if [ -z "$rollback" ]; then pathToConfig="$(nixFlakeBuild "$flake#$flakeAttr.config.system.build.toplevel" "${extraBuildFlags[@]}" "${lockFlags[@]}")" fi copyToTarget "$pathToConfig" - targetHostCmd nix-env -p "$profile" --set "$pathToConfig" + targetHostSudoCmd nix-env -p "$profile" --set "$pathToConfig" elif [[ "$action" = test || "$action" = build || "$action" = dry-build || "$action" = dry-activate ]]; then if [[ -z $flake ]]; then pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A system -k "${extraBuildFlags[@]}")" @@ -695,7 +721,7 @@ if [ -z "$rollback" ]; then fi else # [ -n "$rollback" ] if [[ "$action" = switch || "$action" = boot ]]; then - targetHostCmd nix-env --rollback -p "$profile" + targetHostSudoCmd nix-env --rollback -p "$profile" pathToConfig="$profile" elif [[ "$action" = test || "$action" = build ]]; then systemNumber=$( @@ -740,7 +766,7 @@ if [[ "$action" = switch || "$action" = boot || "$action" = test || "$action" = if [[ -n "$NIXOS_SWITCH_USE_DIRTY_ENV" ]]; then log "warning: skipping systemd-run since NIXOS_SWITCH_USE_DIRTY_ENV is set. This environment variable will be ignored in the future" cmd=() - elif ! targetHostCmd "${cmd[@]}" true &>/dev/null; then + elif ! targetHostSudoCmd "${cmd[@]}" true; then logVerbose "Skipping systemd-run to switch configuration since it is not working in target host." cmd=( "env" @@ -762,7 +788,7 @@ if [[ "$action" = switch || "$action" = boot || "$action" = test || "$action" = fi fi - if ! targetHostCmd "${cmd[@]}" "$action"; then + if ! targetHostSudoCmd "${cmd[@]}" "$action"; then log "warning: error(s) occurred while switching to the new configuration" exit 1 fi |