1 import ./make-test-python.nix ({ pkgs, ...} : {
2 name = "restart-by-activation-script";
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ das_j ];
7 nodes.machine = { pkgs, ... }: {
8 imports = [ ../modules/profiles/minimal.nix ];
10 systemd.services.restart-me = {
11 wantedBy = [ "multi-user.target" ];
14 RemainAfterExit = true;
15 ExecStart = "${pkgs.coreutils}/bin/true";
19 systemd.services.reload-me = {
20 wantedBy = [ "multi-user.target" ];
23 RemainAfterExit = true;
24 ExecStart = "${pkgs.coreutils}/bin/true";
25 ExecReload = ExecStart;
29 system.activationScripts.test = {
30 supportsDryActivation = true;
32 if [ -e /test-the-activation-script ]; then
33 if [ "$NIXOS_ACTION" != dry-activate ]; then
34 touch /activation-was-run
35 echo restart-me.service > /run/nixos/activation-restart-list
36 echo reload-me.service > /run/nixos/activation-reload-list
38 echo restart-me.service > /run/nixos/dry-activation-restart-list
39 echo reload-me.service > /run/nixos/dry-activation-reload-list
46 testScript = /* python */ ''
47 machine.wait_for_unit("multi-user.target")
49 with subtest("nothing happens when the activation script does nothing"):
50 out = machine.succeed("/run/current-system/bin/switch-to-configuration dry-activate 2>&1")
51 assert 'restart' not in out
52 assert 'reload' not in out
53 out = machine.succeed("/run/current-system/bin/switch-to-configuration test")
54 assert 'restart' not in out
55 assert 'reload' not in out
57 machine.succeed("touch /test-the-activation-script")
59 with subtest("dry activation"):
60 out = machine.succeed("/run/current-system/bin/switch-to-configuration dry-activate 2>&1")
61 assert 'would restart the following units: restart-me.service' in out
62 assert 'would reload the following units: reload-me.service' in out
63 machine.fail("test -f /run/nixos/dry-activation-restart-list")
64 machine.fail("test -f /run/nixos/dry-activation-reload-list")
66 with subtest("real activation"):
67 out = machine.succeed("/run/current-system/bin/switch-to-configuration test 2>&1")
68 assert 'restarting the following units: restart-me.service' in out
69 assert 'reloading the following units: reload-me.service' in out
70 machine.fail("test -f /run/nixos/activation-restart-list")
71 machine.fail("test -f /run/nixos/activation-reload-list")