nixos/switch-to-configuration: Never stop system.slice

Problem: Restarting (stopping) system.slice would not only stop X11 but
also most system units/services. We obviously don't want this happening
to users when they switch from 18.03 to 18.09 or nixos-unstable.

Reason: The following change in systemd:
d8e5a93382

The commit adds system.slice to the perpetual units, which means
removing the unit file and adding it to the source code. This is done so
that system.slice can't be stopped anymore but in our case it ironically
would cause this script to stop system.slice because the unit file was
removed (and an older systemd version is still running).

Related issue: https://github.com/NixOS/nixpkgs/issues/39791

(cherry picked from commit 7098b0fcdfd7fa4b82c036d8116b60b78f497316)
Reason: Make sure that this problem wouldn't occur if we would update
the systemd version.
release-18.03-flake
Michael Weiss 2018-05-11 19:13:10 +02:00
parent 1596c81382
commit bb5988dd1c
1 changed files with 18 additions and 0 deletions

View File

@ -167,6 +167,24 @@ while (my ($unit, $state) = each %{$activePrev}) {
if (-e $prevUnitFile && ($state->{state} eq "active" || $state->{state} eq "activating")) {
if (! -e $newUnitFile || abs_path($newUnitFile) eq "/dev/null") {
# Ignore (i.e. never stop) these units:
if ($unit eq "system.slice") {
# TODO: This can be removed a few months after 18.09 is out
# (i.e. after everyone switched away from 18.03).
# Problem: Restarting (stopping) system.slice would not only
# stop X11 but also most system units/services. We obviously
# don't want this happening to users when they switch from 18.03
# to 18.09 or nixos-unstable.
# Reason: The following change in systemd:
# https://github.com/systemd/systemd/commit/d8e5a9338278d6602a0c552f01f298771a384798
# The commit adds system.slice to the perpetual units, which
# means removing the unit file and adding it to the source code.
# This is done so that system.slice can't be stopped anymore but
# in our case it ironically would cause this script to stop
# system.slice because the unit was removed (and an older
# systemd version is still running).
next;
}
my $unitInfo = parseUnit($prevUnitFile);
$unitsToStop{$unit} = 1 if boolIsTrue($unitInfo->{'X-StopOnRemoval'} // "yes");
}