diff --git a/modules/services/x11/xserver.nix b/modules/services/x11/xserver.nix index 5d795e5d57d..5b9cb74169e 100644 --- a/modules/services/x11/xserver.nix +++ b/modules/services/x11/xserver.nix @@ -383,7 +383,7 @@ in { wantedBy = [ "graphical.target" ]; after = [ "systemd-udev-settle.service" ]; - #restartIfChanged = false; + restartIfChanged = false; environment = { FONTCONFIG_FILE = "/etc/fonts/fonts.conf"; # !!! cleanup diff --git a/modules/system/activation/switch-to-configuration.pl b/modules/system/activation/switch-to-configuration.pl index df4c440b97a..a4ca287b420 100644 --- a/modules/system/activation/switch-to-configuration.pl +++ b/modules/system/activation/switch-to-configuration.pl @@ -75,12 +75,23 @@ sub parseFstab { return %res; } +sub parseUnit { + my ($filename) = @_; + my $info = {}; + foreach my $line (read_file($filename)) { + # FIXME: not quite correct. + $line =~ /^([^=]+)=(.*)$/ or next; + $info->{$1} = $2; + } + return $info; +} + # Forget about previously failed services. system("@systemd@/bin/systemctl", "reset-failed"); # Stop all services that no longer exist or have changed in the new # configuration. -my @unitsToStop; +my (@unitsToStop, @unitsToSkip); my $activePrev = getActiveUnits; while (my ($unit, $state) = each %{$activePrev}) { my $baseUnit = $unit; @@ -102,11 +113,16 @@ while (my ($unit, $state) = each %{$activePrev}) { } elsif ($unit =~ /\.socket$/ || $unit =~ /\.path$/) { # FIXME: do something? } else { - # Record that this unit needs to be started below. We - # write this to a file to ensure that the service gets - # restarted if we're interrupted. - write_file($restartListFile, { append => 1 }, "$unit\n"); - push @unitsToStop, $unit; + my $unitInfo = parseUnit($newUnitFile); + if ($unitInfo->{'X-RestartIfChanged'} eq "false") { + push @unitsToSkip, $unit; + } else { + # Record that this unit needs to be started below. We + # write this to a file to ensure that the service gets + # restarted if we're interrupted. + write_file($restartListFile, { append => 1 }, "$unit\n"); + push @unitsToStop, $unit; + } } } } @@ -159,6 +175,9 @@ if (scalar @unitsToStop > 0) { system("@systemd@/bin/systemctl", "stop", "--", @unitsToStop); # FIXME: ignore errors? } +print STDERR "NOT restarting the following units: ", join(", ", sort(@unitsToSkip)), "\n" + if scalar @unitsToSkip > 0; + # Activate the new configuration (i.e., update /etc, make accounts, # and so on). my $res = 0; diff --git a/modules/system/boot/systemd-unit-options.nix b/modules/system/boot/systemd-unit-options.nix index 9aa9b2b4f3b..f56ee4fc0d3 100644 --- a/modules/system/boot/systemd-unit-options.nix +++ b/modules/system/boot/systemd-unit-options.nix @@ -115,6 +115,15 @@ with pkgs.lib; ''; }; + restartIfChanged = mkOption { + type = types.bool; + default = true; + description = '' + Whether the service should be restarted during a NixOS + configuration switch if its definition has changed. + ''; + }; + }; } \ No newline at end of file diff --git a/modules/system/boot/systemd.nix b/modules/system/boot/systemd.nix index 992981f0a36..def5a8bc580 100644 --- a/modules/system/boot/systemd.nix +++ b/modules/system/boot/systemd.nix @@ -199,6 +199,7 @@ let [Service] Environment=PATH=${def.path} ${concatMapStrings (n: "Environment=${n}=${getAttr n def.environment}\n") (attrNames def.environment)} + ${optionalString (!def.restartIfChanged) "X-RestartIfChanged=false"} ${optionalString (def.preStart != "") '' ExecStartPre=${makeJobScript "${name}-prestart.sh" '' diff --git a/modules/system/upstart/upstart.nix b/modules/system/upstart/upstart.nix index 577efe17065..7a498b85439 100644 --- a/modules/system/upstart/upstart.nix +++ b/modules/system/upstart/upstart.nix @@ -54,7 +54,7 @@ let ''; in { - inherit (job) description requires wants before partOf environment path; + inherit (job) description requires wants before partOf environment path restartIfChanged; after = (if job.startOn == "stopped udevtrigger" then [ "systemd-udev-settle.service" ] else @@ -185,15 +185,6 @@ let ''; }; - restartIfChanged = mkOption { - type = types.bool; - default = true; - description = '' - Whether the job should be restarted if it has changed after a - NixOS configuration switch. - ''; - }; - task = mkOption { type = types.bool; default = false; @@ -302,8 +293,6 @@ in config = { - system.build.upstart = "/no-upstart"; - boot.systemd.services = flip mapAttrs' config.jobs (name: job: nameValuePair "${job.name}.service" job.unit);