diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2023-10-13 18:01:31 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-13 18:01:31 +0000 |
commit | c68d98e9d41f96cf3d591f8d5a7abfdb2b292799 (patch) | |
tree | be6df5adcc1528f56a1204acff4eaf2cfd1cefb6 /pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh | |
parent | 68ba5fd2ed8be749cf1865ed9a71667dfda944a7 (diff) | |
parent | 4a7eb88e55f80623bb3ea4968ff4600814016ffb (diff) | |
download | nixlib-c68d98e9d41f96cf3d591f8d5a7abfdb2b292799.tar nixlib-c68d98e9d41f96cf3d591f8d5a7abfdb2b292799.tar.gz nixlib-c68d98e9d41f96cf3d591f8d5a7abfdb2b292799.tar.bz2 nixlib-c68d98e9d41f96cf3d591f8d5a7abfdb2b292799.tar.lz nixlib-c68d98e9d41f96cf3d591f8d5a7abfdb2b292799.tar.xz nixlib-c68d98e9d41f96cf3d591f8d5a7abfdb2b292799.tar.zst nixlib-c68d98e9d41f96cf3d591f8d5a7abfdb2b292799.zip |
Merge staging-next into staging
Diffstat (limited to 'pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh')
-rwxr-xr-x | pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh index 2f89642845e2..68e00690652e 100755 --- a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh +++ b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh @@ -653,18 +653,48 @@ fi # If we're not just building, then make the new configuration the boot # default and/or activate it now. if [[ "$action" = switch || "$action" = boot || "$action" = test || "$action" = dry-activate ]]; then + # Using systemd-run here to protect against PTY failures/network + # disconnections during rebuild. + # See: https://github.com/NixOS/nixpkgs/issues/39118 + cmd=( + "systemd-run" + "-E" "LOCALE_ARCHIVE" # Will be set to new value early in switch-to-configuration script, but interpreter starts out with old value + "--collect" + "--no-ask-password" + "--pty" + "--quiet" + "--same-dir" + "--service-type=exec" + "--unit=nixos-rebuild-switch-to-configuration" + "--wait" + ) + # Check if we have a working systemd-run. In chroot environments we may have + # a non-working systemd, so we fallback to not using systemd-run. + # You may also want to explicitly set NIXOS_SWITCH_USE_DIRTY_ENV environment + # variable, since systemd-run runs inside an isolated environment and + # this may break some post-switch scripts. However keep in mind that this + # may be dangerous in remote access (e.g. SSH). + 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 + logVerbose "Skipping systemd-run to switch configuration since it is not working in target host." + cmd=("env" "-i" "LOCALE_ARCHIVE=$LOCALE_ARCHIVE") + else + logVerbose "Using systemd-run to switch configuration." + fi if [[ -z "$specialisation" ]]; then - cmd="$pathToConfig/bin/switch-to-configuration" + cmd+=("$pathToConfig/bin/switch-to-configuration") else - cmd="$pathToConfig/specialisation/$specialisation/bin/switch-to-configuration" + cmd+=("$pathToConfig/specialisation/$specialisation/bin/switch-to-configuration") - if [[ ! -f "$cmd" ]]; then + if [[ ! -f "${cmd[-1]}" ]]; then log "error: specialisation not found: $specialisation" exit 1 fi fi - if ! targetHostCmd "$cmd" "$action"; then + if ! targetHostCmd "${cmd[@]}" "$action"; then log "warning: error(s) occurred while switching to the new configuration" exit 1 fi |