Merge pull request #148751 from NixOS/feat/slight-stc-improvements

nixos/switch-to-configuration: Add small improvements

authored by Bernardo Meurer and committed by GitHub ebb7f07e be1c35e2

+21 -9
+14 -9
nixos/modules/system/activation/switch-to-configuration.pl
··· 11 11 12 12 my $out = "@out@"; 13 13 14 - # FIXME: maybe we should use /proc/1/exe to get the current systemd. 15 14 my $curSystemd = abs_path("/run/current-system/sw/bin"); 16 15 17 16 # To be robust against interruption, record what units need to be started etc. ··· 25 24 my $dryRestartByActivationFile = "/run/nixos/dry-activation-restart-list"; 26 25 my $dryReloadByActivationFile = "/run/nixos/dry-activation-reload-list"; 27 26 28 - make_path("/run/nixos", { mode => 0755 }); 27 + make_path("/run/nixos", { mode => oct(755) }); 29 28 30 29 my $action = shift @ARGV; 31 30 ··· 219 218 } 220 219 221 220 elsif (fingerprintUnit($prevUnitFile) ne fingerprintUnit($newUnitFile)) { 222 - if ($unit eq "sysinit.target" || $unit eq "basic.target" || $unit eq "multi-user.target" || $unit eq "graphical.target") { 221 + if ($unit eq "sysinit.target" || $unit eq "basic.target" || $unit eq "multi-user.target" || $unit eq "graphical.target" || $unit =~ /\.path$/ || $unit =~ /\.slice$/) { 223 222 # Do nothing. These cannot be restarted directly. 223 + 224 + # Slices and Paths don't have to be restarted since 225 + # properties (resource limits and inotify watches) 226 + # seem to get applied on daemon-reload. 224 227 } elsif ($unit =~ /\.mount$/) { 225 228 # Reload the changed mount unit to force a remount. 226 229 $unitsToReload{$unit} = 1; 227 230 recordUnit($reloadListFile, $unit); 228 - } elsif ($unit =~ /\.socket$/ || $unit =~ /\.path$/ || $unit =~ /\.slice$/) { 231 + } elsif ($unit =~ /\.socket$/) { 229 232 # FIXME: do something? 230 233 } else { 231 234 my $unitInfo = parseUnit($newUnitFile); ··· 382 385 split('\n', read_file($dryReloadByActivationFile, err_mode => 'quiet') // ""); 383 386 384 387 print STDERR "would restart systemd\n" if $restartSystemd; 388 + print STDERR "would reload the following units: ", join(", ", sort(keys %unitsToReload)), "\n" 389 + if scalar(keys %unitsToReload) > 0; 385 390 print STDERR "would restart the following units: ", join(", ", sort(keys %unitsToRestart)), "\n" 386 391 if scalar(keys %unitsToRestart) > 0; 387 392 print STDERR "would start the following units: ", join(", ", @unitsToStartFiltered), "\n" 388 393 if scalar @unitsToStartFiltered; 389 - print STDERR "would reload the following units: ", join(", ", sort(keys %unitsToReload)), "\n" 390 - if scalar(keys %unitsToReload) > 0; 391 394 unlink($dryRestartByActivationFile); 392 395 unlink($dryReloadByActivationFile); 393 396 exit 0; ··· 400 403 print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n" 401 404 if scalar @unitsToStopFiltered; 402 405 # Use current version of systemctl binary before daemon is reexeced. 403 - system("$curSystemd/systemctl", "stop", "--", sort(keys %unitsToStop)); # FIXME: ignore errors? 406 + system("$curSystemd/systemctl", "stop", "--", sort(keys %unitsToStop)); 404 407 } 405 408 406 409 print STDERR "NOT restarting the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n" ··· 485 488 486 489 487 490 # Print failed and new units. 488 - my (@failed, @new, @restarting); 491 + my (@failed, @new); 489 492 my $activeNew = getActiveUnits; 490 493 while (my ($unit, $state) = each %{$activeNew}) { 491 494 if ($state->{state} eq "failed") { ··· 501 504 push @failed, $unit; 502 505 } 503 506 } 504 - elsif ($state->{state} ne "failed" && !defined $activePrev->{$unit}) { 507 + # Ignore scopes since they are not managed by this script but rather 508 + # created and managed by third-party services via the systemd dbus API. 509 + elsif ($state->{state} ne "failed" && !defined $activePrev->{$unit} && $unit !~ /\.scope$/) { 505 510 push @new, $unit; 506 511 } 507 512 }
+7
nixos/modules/system/activation/top-level.nix
··· 78 78 export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive" 79 79 substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration 80 80 chmod +x $out/bin/switch-to-configuration 81 + ${optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) '' 82 + if ! output=$($perl/bin/perl -c $out/bin/switch-to-configuration 2>&1); then 83 + echo "switch-to-configuration syntax is not valid:" 84 + echo "$output" 85 + exit 1 86 + fi 87 + ''} 81 88 82 89 echo -n "${toString config.system.extraDependencies}" > $out/extra-dependencies 83 90