From 2f6148c7433c08c7b32e772f7557fd08d39f48ab Mon Sep 17 00:00:00 2001 From: Gleb Peregud Date: Sat, 18 Nov 2017 23:33:24 +0100 Subject: [PATCH 1/2] nixos/system: make switch-to-configuration script pure. Fixes #28443 Fixed few invocations to `systemctl` to have an absolute path. Additionally add LOCALE_ARCHIVE so that perl stops spewing warning messages. --- .../activation/switch-to-configuration.pl | 13 +++++++--- nixos/modules/system/activation/top-level.nix | 2 +- nixos/tests/switch-test.nix | 25 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 nixos/tests/switch-test.nix diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl index 29cc60b00324..87a4ab2a586d 100644 --- a/nixos/modules/system/activation/switch-to-configuration.pl +++ b/nixos/modules/system/activation/switch-to-configuration.pl @@ -16,6 +16,10 @@ my $reloadListFile = "/run/systemd/reload-list"; my $action = shift @ARGV; +if ("@localeArchive@" ne "") { + $ENV{LOCALE_ARCHIVE} = "@localeArchive@"; +} + if (!defined $action || ($action ne "switch" && $action ne "boot" && $action ne "test" && $action ne "dry-activate")) { print STDERR <; chomp $escaped; @@ -364,7 +370,8 @@ syslog(LOG_NOTICE, "switching to system configuration $out"); if (scalar (keys %unitsToStop) > 0) { print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n" if scalar @unitsToStopFiltered; - system("systemctl", "stop", "--", sort(keys %unitsToStop)); # FIXME: ignore errors? + # Use current version of systemctl binary before daemon is reexeced. + system("/run/current-system/sw/bin/systemctl", "stop", "--", sort(keys %unitsToStop)); # FIXME: ignore errors? } print STDERR "NOT restarting the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n" diff --git a/nixos/modules/system/activation/top-level.nix b/nixos/modules/system/activation/top-level.nix index 67cb2264e3f3..0c50241f2edf 100644 --- a/nixos/modules/system/activation/top-level.nix +++ b/nixos/modules/system/activation/top-level.nix @@ -26,7 +26,6 @@ let cloner false config.nesting.children ++ cloner true config.nesting.clone; - systemBuilder = let kernelPath = "${config.boot.kernelPackages.kernel}/" + @@ -83,6 +82,7 @@ let done mkdir $out/bin + export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive" substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration chmod +x $out/bin/switch-to-configuration diff --git a/nixos/tests/switch-test.nix b/nixos/tests/switch-test.nix new file mode 100644 index 000000000000..46f2563af8d9 --- /dev/null +++ b/nixos/tests/switch-test.nix @@ -0,0 +1,25 @@ +# Test configuration switching. + +import ./make-test.nix ({ pkgs, ...} : { + name = "switch-test"; + meta = with pkgs.stdenv.lib.maintainers; { + maintainers = [ gleber ]; + }; + + nodes = { + machine = { config, lib, pkgs, ... }: { + users.mutableUsers = false; + }; + other = { config, lib, pkgs, ... }: { + users.mutableUsers = true; + }; + }; + + testScript = {nodes, ...}: let + originalSystem = nodes.machine.config.system.build.toplevel; + otherSystem = nodes.other.config.system.build.toplevel; + in '' + $machine->succeed("env -i ${originalSystem}/bin/switch-to-configuration test | tee /dev/stderr"); + $machine->succeed("env -i ${otherSystem}/bin/switch-to-configuration test | tee /dev/stderr"); + ''; +}) From f8fb6a679e060ae84e9e4ffdb7cb99c51d7f4003 Mon Sep 17 00:00:00 2001 From: Gleb Peregud Date: Sun, 19 Nov 2017 19:50:08 +0100 Subject: [PATCH 2/2] nixos/release: add nixos/tests/switch-test.nix to tested job --- nixos/release-combined.nix | 1 + nixos/release.nix | 1 + 2 files changed, 2 insertions(+) diff --git a/nixos/release-combined.nix b/nixos/release-combined.nix index 125e6b7050bc..e12da703f8d7 100644 --- a/nixos/release-combined.nix +++ b/nixos/release-combined.nix @@ -114,6 +114,7 @@ in rec { (all nixos.tests.sddm.default) (all nixos.tests.simple) (all nixos.tests.slim) + (all nixos.tests.switchTest) (all nixos.tests.udisks2) (all nixos.tests.xfce) diff --git a/nixos/release.nix b/nixos/release.nix index 28eb76d888e4..cad3f96828a1 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -327,6 +327,7 @@ in rec { tests.slim = callTest tests/slim.nix {}; tests.smokeping = callTest tests/smokeping.nix {}; tests.snapper = callTest tests/snapper.nix {}; + tests.switchTest = callTest tests/switch-test.nix {}; tests.taskserver = callTest tests/taskserver.nix {}; tests.tomcat = callTest tests/tomcat.nix {}; tests.udisks2 = callTest tests/udisks2.nix {};