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 17 my $action = shift @ARGV; 18 19 if (!defined $action || ($action ne "switch" && $action ne "boot" && $action ne "test" && $action ne "dry-activate")) { 20 print STDERR <<EOF; 21 Usage: $0 [switch|boot|test] ··· 65 sub getActiveUnits { 66 # FIXME: use D-Bus or whatever to query this, since parsing the 67 # output of list-units is likely to break. 68 - my $lines = `LANG= systemctl list-units --full --no-legend`; 69 my $res = {}; 70 foreach my $line (split '\n', $lines) { 71 chomp $line; ··· 262 263 sub pathToUnitName { 264 my ($path) = @_; 265 - open my $cmd, "-|", "@systemd@/bin/systemd-escape", "--suffix=mount", "-p", $path 266 or die "Unable to escape $path!\n"; 267 my $escaped = join "", <$cmd>; 268 chomp $escaped; ··· 364 if (scalar (keys %unitsToStop) > 0) { 365 print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n" 366 if scalar @unitsToStopFiltered; 367 - system("systemctl", "stop", "--", sort(keys %unitsToStop)); # FIXME: ignore errors? 368 } 369 370 print STDERR "NOT restarting the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n"
··· 16 17 my $action = shift @ARGV; 18 19 + if ("@localeArchive@" ne "") { 20 + $ENV{LOCALE_ARCHIVE} = "@localeArchive@"; 21 + } 22 + 23 if (!defined $action || ($action ne "switch" && $action ne "boot" && $action ne "test" && $action ne "dry-activate")) { 24 print STDERR <<EOF; 25 Usage: $0 [switch|boot|test] ··· 69 sub getActiveUnits { 70 # FIXME: use D-Bus or whatever to query this, since parsing the 71 # output of list-units is likely to break. 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`; 74 my $res = {}; 75 foreach my $line (split '\n', $lines) { 76 chomp $line; ··· 267 268 sub pathToUnitName { 269 my ($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 272 or die "Unable to escape $path!\n"; 273 my $escaped = join "", <$cmd>; 274 chomp $escaped; ··· 370 if (scalar (keys %unitsToStop) > 0) { 371 print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n" 372 if scalar @unitsToStopFiltered; 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? 375 } 376 377 print STDERR "NOT restarting the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n"
+1 -1
nixos/modules/system/activation/top-level.nix
··· 26 cloner false config.nesting.children 27 ++ cloner true config.nesting.clone; 28 29 - 30 systemBuilder = 31 let 32 kernelPath = "${config.boot.kernelPackages.kernel}/" + ··· 83 done 84 85 mkdir $out/bin 86 substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration 87 chmod +x $out/bin/switch-to-configuration 88
··· 26 cloner false config.nesting.children 27 ++ cloner true config.nesting.clone; 28 29 systemBuilder = 30 let 31 kernelPath = "${config.boot.kernelPackages.kernel}/" + ··· 82 done 83 84 mkdir $out/bin 85 + export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive" 86 substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration 87 chmod +x $out/bin/switch-to-configuration 88
+1
nixos/release-combined.nix
··· 116 (all nixos.tests.sddm.default) 117 (all nixos.tests.simple) 118 (all nixos.tests.slim) 119 (all nixos.tests.udisks2) 120 (all nixos.tests.xfce) 121
··· 116 (all nixos.tests.sddm.default) 117 (all nixos.tests.simple) 118 (all nixos.tests.slim) 119 + (all nixos.tests.switchTest) 120 (all nixos.tests.udisks2) 121 (all nixos.tests.xfce) 122
+1
nixos/release.nix
··· 331 tests.slim = callTest tests/slim.nix {}; 332 tests.smokeping = callTest tests/smokeping.nix {}; 333 tests.snapper = callTest tests/snapper.nix {}; 334 tests.taskserver = callTest tests/taskserver.nix {}; 335 tests.tomcat = callTest tests/tomcat.nix {}; 336 tests.udisks2 = callTest tests/udisks2.nix {};
··· 331 tests.slim = callTest tests/slim.nix {}; 332 tests.smokeping = callTest tests/smokeping.nix {}; 333 tests.snapper = callTest tests/snapper.nix {}; 334 + tests.switchTest = callTest tests/switch-test.nix {}; 335 tests.taskserver = callTest tests/taskserver.nix {}; 336 tests.tomcat = callTest tests/tomcat.nix {}; 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 + })