blob: f43332af033fc54ccd7d70a6fdc224e20dc38116 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
{ lib, ... }:
{
name = "user-activation-scripts";
meta = with lib.maintainers; {
maintainers = [ chkno ];
};
nodes.machine = {
system.switch.enable = true;
system.userActivationScripts.foo = "mktemp ~/user-activation-ran.XXXXXX";
users.users.alice = {
initialPassword = "pass1";
isNormalUser = true;
};
systemd.user.tmpfiles.users.alice.rules = [ "r %h/file-to-remove" ];
specialisation.changed.configuration.system.userActivationScripts.bar = "true";
};
testScript = ''
def verify_user_activation_run_count(n):
t.assertEqual(
n,
int(machine.succeed('find /home/alice/ -name user-activation-ran.\\* | wc -l').rstrip())
)
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("getty@tty1.service")
machine.wait_until_tty_matches("1", "login: ")
machine.send_chars("alice\n")
machine.wait_until_tty_matches("1", "Password: ")
machine.send_chars("pass1\n")
machine.send_chars("touch login-ok\n")
machine.wait_for_file("/home/alice/login-ok")
verify_user_activation_run_count(1)
machine.succeed("touch /home/alice/file-to-remove")
machine.succeed("/run/current-system/bin/switch-to-configuration test")
verify_user_activation_run_count(2)
machine.succeed("[[ ! -f /home/alice/file-to-remove ]] || false")
# Activation must not be killed while running.
machine.fail("journalctl -b _SYSTEMD_USER_UNIT=nixos-activation.service | grep -q 'code=killed'")
# Changed activation script: still exactly one run.
machine.succeed("/run/current-system/specialisation/changed/bin/switch-to-configuration test")
verify_user_activation_run_count(3)
machine.fail("journalctl -b _SYSTEMD_USER_UNIT=nixos-activation.service | grep -q 'code=killed'")
'';
}
|