git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #31805 from gleber/make-switch-to-configuration-pure

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

commitedcf51a359d87c2ce8cdcfcf8b32b96cfc00ec81 authorobadz <obadz-git@obadz.com> dateSun 19 Nov 2017, 19:03 (9 years ago) parentf367bb4f8fb6a6
5 files changed+38−4
nixos/modules/system/activation/switch-to-configuration.pl+10−3 nixos/modules/system/activation/top-level.nix+1−1 nixos/release-combined.nix+1 nixos/release.nix+1 nixos/tests/switch-test.nix+25
nixos/modules/system/activation/switch-to-configuration.pl+10−3
@@ -16,6 +16,10 @@ my $reloadListFile = "/run/systemd/reload-list";
1616
1717my $action = shift @ARGV;
1818
19+if ("@localeArchive@" ne "") {
20+ $ENV{LOCALE_ARCHIVE} = "@localeArchive@";
21+}
22+
1923if (!defined $action || ($action ne "switch" && $action ne "boot" && $action ne "test" && $action ne "dry-activate")) {
2024 print STDERR <<EOF;
2125Usage: $0 [switch|boot|test]
@@ -65,7 +69,8 @@ $SIG{PIPE} = "IGNORE";
6569sub getActiveUnits {
6670 # FIXME: use D-Bus or whatever to query this, since parsing the
6771 # 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`;
6974 my $res = {};
7075 foreach my $line (split '\n', $lines) {
7176 chomp $line;
@@ -262,7 +267,8 @@ while (my ($unit, $state) = each %{$activePrev}) {
262267
263268sub pathToUnitName {
264269 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
266272 or die "Unable to escape $path!\n";
267273 my $escaped = join "", <$cmd>;
268274 chomp $escaped;
@@ -364,7 +370,8 @@ syslog(LOG_NOTICE, "switching to system configuration $out");
364370if (scalar (keys %unitsToStop) > 0) {
365371 print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n"
366372 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?
368375}
369376
370377print STDERR "NOT restarting the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n"
nixos/modules/system/activation/top-level.nix+1−1
@@ -26,7 +26,6 @@ let
2626 cloner false config.nesting.children
2727 ++ cloner true config.nesting.clone;
2828
29−
3029 systemBuilder =
3130 let
3231 kernelPath = "${config.boot.kernelPackages.kernel}/" +
@@ -83,6 +82,7 @@ let
8382 done
8483
8584 mkdir $out/bin
85+ export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive"
8686 substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration
8787 chmod +x $out/bin/switch-to-configuration
8888
nixos/release-combined.nix+1
@@ -116,6 +116,7 @@ in rec {
116116 (all nixos.tests.sddm.default)
117117 (all nixos.tests.simple)
118118 (all nixos.tests.slim)
119+ (all nixos.tests.switchTest)
119120 (all nixos.tests.udisks2)
120121 (all nixos.tests.xfce)
121122
nixos/release.nix+1
@@ -331,6 +331,7 @@ in rec {
331331 tests.slim = callTest tests/slim.nix {};
332332 tests.smokeping = callTest tests/smokeping.nix {};
333333 tests.snapper = callTest tests/snapper.nix {};
334+ tests.switchTest = callTest tests/switch-test.nix {};
334335 tests.taskserver = callTest tests/taskserver.nix {};
335336 tests.tomcat = callTest tests/tomcat.nix {};
336337 tests.udisks2 = callTest tests/udisks2.nix {};
nixos/tests/switch-test.nixnew file+25
@@ -0,0 +1,25 @@
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+})