From 40b7674b98ea79a540908b36c2d72add66a35218 Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Mon, 4 Nov 2024 00:51:58 -0500 Subject: [PATCH 1/4] nixos/tests/switchTest: Test no boot loader --- nixos/tests/switch-test.nix | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/nixos/tests/switch-test.nix b/nixos/tests/switch-test.nix index e00c22b81682..617f4d67d577 100644 --- a/nixos/tests/switch-test.nix +++ b/nixos/tests/switch-test.nix @@ -53,11 +53,8 @@ in { environment.systemPackages = [ pkgs.socat ]; # for the socket activation stuff users.mutableUsers = false; - # For boot/switch testing - system.build.installBootLoader = lib.mkForce (pkgs.writeShellScript "install-dummy-loader" '' - echo "installing dummy bootloader" - touch /tmp/bootloader-installed - ''); + # Test that no boot loader still switches, e.g. in the ISO + boot.loader.grub.enable = false; specialisation = rec { brokenInitInterface.configuration.config.system.extraSystemBuilderCmds = '' @@ -672,22 +669,18 @@ in { "${stderrRunner} ${otherSystem}/bin/switch-to-configuration test" ) + boot_loader_text = "Warning: do not know how to make this configuration bootable; please enable a boot loader." with subtest("actions"): # boot action - machine.fail("test -f /tmp/bootloader-installed") out = switch_to_specialisation("${machine}", "simpleService", action="boot") - assert_contains(out, "installing dummy bootloader") + assert_contains(out, boot_loader_text) assert_lacks(out, "activating the configuration...") # good indicator of a system activation - machine.succeed("test -f /tmp/bootloader-installed") - machine.succeed("rm /tmp/bootloader-installed") # switch action - machine.fail("test -f /tmp/bootloader-installed") out = switch_to_specialisation("${machine}", "", action="switch") - assert_contains(out, "installing dummy bootloader") + assert_contains(out, boot_loader_text) assert_contains(out, "activating the configuration...") # good indicator of a system activation - machine.succeed("test -f /tmp/bootloader-installed") # test and dry-activate actions are tested further down below @@ -795,7 +788,7 @@ in { # Start a simple service out = switch_to_specialisation("${machine}", "simpleService") - assert_lacks(out, "installing dummy bootloader") # test does not install a bootloader + assert_lacks(out, boot_loader_text) # test does not install a bootloader assert_lacks(out, "stopping the following units:") assert_lacks(out, "NOT restarting the following changed units:") assert_contains(out, "reloading the following units: ${dbusService}\n") # huh @@ -872,7 +865,7 @@ in { # Ensure the service can be started when the activation script isn't in toplevel # This is a lot like "Start a simple service", except activation-only deps could be gc-ed out = run_switch("${nodes.machine.specialisation.simpleServiceSeparateActivationScript.configuration.system.build.separateActivationScript}/bin/switch-to-configuration"); - assert_lacks(out, "installing dummy bootloader") # test does not install a bootloader + assert_lacks(out, boot_loader_text) # test does not install a bootloader assert_lacks(out, "stopping the following units:") assert_lacks(out, "NOT restarting the following changed units:") assert_contains(out, "reloading the following units: ${dbusService}\n") # huh From a7cda6835fc042a0a70d3e1983863aad0183d229 Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Mon, 4 Nov 2024 00:51:58 -0500 Subject: [PATCH 2/4] nixos/tests/switchTest: Remove spurious dbus reload checks Previously, the base system had grub in `systemPackages` but the specialisations did not. This is because of a few factors: - Grub was enabled in the nixos config - Specialisations set `grub.device = "nodev"` (see: system/activation/no-clone.nix) - Grub is added to `systemPackages` depending on whether `devices == ["nodev"]` This meant that switching between the base system and a specialisation always changed `system-path.drv`, which is a reload trigger for dbus. With grub disabled in this test, this no longer happens. --- nixos/tests/switch-test.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/nixos/tests/switch-test.nix b/nixos/tests/switch-test.nix index 617f4d67d577..98b145c58e81 100644 --- a/nixos/tests/switch-test.nix +++ b/nixos/tests/switch-test.nix @@ -742,7 +742,7 @@ in { out = switch_to_specialisation("${machine}", "") assert_contains(out, "stopping the following units: test.mount\n") assert_lacks(out, "NOT restarting the following changed units:") - assert_contains(out, "reloading the following units: ${dbusService}\n") + assert_lacks(out, "reloading the following units:") assert_lacks(out, "\nrestarting the following units:") assert_lacks(out, "\nstarting the following units:") assert_lacks(out, "the following new units were started:") @@ -750,7 +750,7 @@ in { out = switch_to_specialisation("${machine}", "storeMountModified") assert_lacks(out, "stopping the following units:") assert_contains(out, "NOT restarting the following changed units: -.mount") - assert_contains(out, "reloading the following units: ${dbusService}\n") + assert_lacks(out, "reloading the following units:") assert_lacks(out, "\nrestarting the following units:") assert_lacks(out, "\nstarting the following units:") assert_lacks(out, "the following new units were started:") @@ -761,7 +761,7 @@ in { out = switch_to_specialisation("${machine}", "swap") assert_lacks(out, "stopping the following units:") assert_lacks(out, "NOT restarting the following changed units:") - assert_contains(out, "reloading the following units: ${dbusService}\n") + assert_lacks(out, "reloading the following units:") assert_lacks(out, "\nrestarting the following units:") assert_lacks(out, "\nstarting the following units:") assert_contains(out, "the following new units were started: swapfile.swap") @@ -770,7 +770,7 @@ in { assert_contains(out, "stopping swap device: /swapfile") assert_lacks(out, "stopping the following units:") assert_lacks(out, "NOT restarting the following changed units:") - assert_contains(out, "reloading the following units: ${dbusService}\n") + assert_lacks(out, "reloading the following units:") assert_lacks(out, "\nrestarting the following units:") assert_lacks(out, "\nstarting the following units:") assert_lacks(out, "the following new units were started:") @@ -791,7 +791,7 @@ in { assert_lacks(out, boot_loader_text) # test does not install a bootloader assert_lacks(out, "stopping the following units:") assert_lacks(out, "NOT restarting the following changed units:") - assert_contains(out, "reloading the following units: ${dbusService}\n") # huh + assert_lacks(out, "reloading the following units:") assert_lacks(out, "\nrestarting the following units:") assert_lacks(out, "\nstarting the following units:") assert_contains(out, "the following new units were started: test.service\n") @@ -868,7 +868,7 @@ in { assert_lacks(out, boot_loader_text) # test does not install a bootloader assert_lacks(out, "stopping the following units:") assert_lacks(out, "NOT restarting the following changed units:") - assert_contains(out, "reloading the following units: ${dbusService}\n") # huh + assert_lacks(out, "reloading the following units:") assert_lacks(out, "\nrestarting the following units:") assert_lacks(out, "\nstarting the following units:") assert_contains(out, "the following new units were started: test.service\n") From f92ec1bc93990197895f4ce4bcf29354a738f830 Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Mon, 4 Nov 2024 00:51:58 -0500 Subject: [PATCH 3/4] nixos/tests/switchTest: Add test for dbus reloading --- nixos/tests/switch-test.nix | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/nixos/tests/switch-test.nix b/nixos/tests/switch-test.nix index 98b145c58e81..a55155579b4b 100644 --- a/nixos/tests/switch-test.nix +++ b/nixos/tests/switch-test.nix @@ -593,6 +593,19 @@ in { imports = [ slice.configuration ]; systemd.slices.testslice.sliceConfig.MemoryMax = lib.mkForce null; }; + + dbusReload.configuration = { config, ... }: let + dbusService = { + "dbus" = "dbus"; + "broker" = "dbus-broker"; + }.${config.services.dbus.implementation}; + in { + # We want to make sure that stc catches this as a reload, + # not a restart. + systemd.services.${dbusService}.restartTriggers = [ + (pkgs.writeText "dbus-reload-dummy" "dbus reload dummy") + ]; + }; }; }; @@ -1422,5 +1435,15 @@ in { assert_lacks(out, "the following new units were started:") machine.succeed("systemctl start testservice.service") machine.succeed("echo 1 > /proc/sys/vm/panic_on_oom") # disallow OOMing + + with subtest("dbus reloads"): + out = switch_to_specialisation("${machine}", "") + out = switch_to_specialisation("${machine}", "dbusReload") + assert_lacks(out, "stopping the following units:") + assert_lacks(out, "NOT restarting the following changed units:") + assert_contains(out, "reloading the following units: ${dbusService}\n") + assert_lacks(out, "\nrestarting the following units:") + assert_lacks(out, "\nstarting the following units:") + assert_lacks(out, "the following new units were started:") ''; }) From 5d9ac94606923cadc983c508dc065213e64e055f Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Sun, 3 Nov 2024 18:49:17 -0500 Subject: [PATCH 4/4] nixos/activation-script: Make `installBootLoader` default a script Fixes #344535 --- .../modules/system/activation/activation-script.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nixos/modules/system/activation/activation-script.nix b/nixos/modules/system/activation/activation-script.nix index 14e7769ca8fe..e052241acfd7 100644 --- a/nixos/modules/system/activation/activation-script.nix +++ b/nixos/modules/system/activation/activation-script.nix @@ -205,10 +205,14 @@ in system.build.installBootLoader = mkOption { internal = true; - # "; true" => make the `$out` argument from switch-to-configuration.pl - # go to `true` instead of `echo`, hiding the useless path - # from the log. - default = "echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2; true"; + default = pkgs.writeShellScript "no-bootloader" '' + echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2 + ''; + defaultText = lib.literalExpression '' + pkgs.writeShellScript "no-bootloader" ''' + echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2 + ''' + ''; description = '' A program that writes a bootloader installation script to the path passed in the first command line argument.