Merge pull request #31805 from gleber/make-switch-to-configuration-pure

nixos/system: make switch-to-configuration script pure

authored by obadz and committed by GitHub edcf51a3 f367bb4d

+38 -4
+10 -3
nixos/modules/system/activation/switch-to-configuration.pl
··· 16 16 17 17 my $action = shift @ARGV; 18 18 19 + if ("@localeArchive@" ne "") { 20 + $ENV{LOCALE_ARCHIVE} = "@localeArchive@"; 21 + } 22 + 19 23 if (!defined $action || ($action ne "switch" && $action ne "boot" && $action ne "test" && $action ne "dry-activate")) { 20 24 print STDERR <<EOF; 21 25 Usage: $0 [switch|boot|test] ··· 65 69 sub getActiveUnits { 66 70 # FIXME: use D-Bus or whatever to query this, since parsing the 67 71 # output of list-units is likely to break. 68 - my $lines = `LANG= systemctl list-units --full --no-legend`; 72 + # Use current version of systemctl binary before daemon is reexeced. 73 + my $lines = `LANG= /run/current-system/sw/bin/systemctl list-units --full --no-legend`; 69 74 my $res = {}; 70 75 foreach my $line (split '\n', $lines) { 71 76 chomp $line; ··· 262 267 263 268 sub pathToUnitName { 264 269 my ($path) = @_; 265 - open my $cmd, "-|", "@systemd@/bin/systemd-escape", "--suffix=mount", "-p", $path 270 + # Use current version of systemctl binary before daemon is reexeced. 271 + open my $cmd, "-|", "/run/current-system/sw/bin/systemd-escape", "--suffix=mount", "-p", $path 266 272 or die "Unable to escape $path!\n"; 267 273 my $escaped = join "", <$cmd>; 268 274 chomp $escaped; ··· 364 370 if (scalar (keys %unitsToStop) > 0) { 365 371 print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n" 366 372 if scalar @unitsToStopFiltered; 367 - system("systemctl", "stop", "--", sort(keys %unitsToStop)); # FIXME: ignore errors? 373 + # Use current version of systemctl binary before daemon is reexeced. 374 + system("/run/current-system/sw/bin/systemctl", "stop", "--", sort(keys %unitsToStop)); # FIXME: ignore errors? 368 375 } 369 376 370 377 print STDERR "NOT restarting the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n"
+1 -1
nixos/modules/system/activation/top-level.nix
··· 26 26 cloner false config.nesting.children 27 27 ++ cloner true config.nesting.clone; 28 28 29 - 30 29 systemBuilder = 31 30 let 32 31 kernelPath = "${config.boot.kernelPackages.kernel}/" + ··· 83 82 done 84 83 85 84 mkdir $out/bin 85 + export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive" 86 86 substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration 87 87 chmod +x $out/bin/switch-to-configuration 88 88
+1
nixos/release-combined.nix
··· 116 116 (all nixos.tests.sddm.default) 117 117 (all nixos.tests.simple) 118 118 (all nixos.tests.slim) 119 + (all nixos.tests.switchTest) 119 120 (all nixos.tests.udisks2) 120 121 (all nixos.tests.xfce) 121 122
+1
nixos/release.nix
··· 331 331 tests.slim = callTest tests/slim.nix {}; 332 332 tests.smokeping = callTest tests/smokeping.nix {}; 333 333 tests.snapper = callTest tests/snapper.nix {}; 334 + tests.switchTest = callTest tests/switch-test.nix {}; 334 335 tests.taskserver = callTest tests/taskserver.nix {}; 335 336 tests.tomcat = callTest tests/tomcat.nix {}; 336 337 tests.udisks2 = callTest tests/udisks2.nix {};
+25
nixos/tests/switch-test.nix
··· 1 + # Test configuration switching. 2 + 3 + import ./make-test.nix ({ pkgs, ...} : { 4 + name = "switch-test"; 5 + meta = with pkgs.stdenv.lib.maintainers; { 6 + maintainers = [ gleber ]; 7 + }; 8 + 9 + nodes = { 10 + machine = { config, lib, pkgs, ... }: { 11 + users.mutableUsers = false; 12 + }; 13 + other = { config, lib, pkgs, ... }: { 14 + users.mutableUsers = true; 15 + }; 16 + }; 17 + 18 + testScript = {nodes, ...}: let 19 + originalSystem = nodes.machine.config.system.build.toplevel; 20 + otherSystem = nodes.other.config.system.build.toplevel; 21 + in '' 22 + $machine->succeed("env -i ${originalSystem}/bin/switch-to-configuration test | tee /dev/stderr"); 23 + $machine->succeed("env -i ${otherSystem}/bin/switch-to-configuration test | tee /dev/stderr"); 24 + ''; 25 + })