about summary refs log tree commit diff
path: root/nixos/tests/user-activation-scripts.nix
blob: 5df072ce0508a9837bf98b5e0bcdfd05732fa83d (plain) (blame)
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
import ./make-test-python.nix ({ lib, ... }: {
  name = "user-activation-scripts";
  meta = with lib.maintainers; { maintainers = [ chkno ]; };

  nodes.machine = {
    system.userActivationScripts.foo = "mktemp ~/user-activation-ran.XXXXXX";
    users.users.alice = {
      initialPassword = "pass1";
      isNormalUser = true;
    };
  };

  testScript = ''
    def verify_user_activation_run_count(n):
        machine.succeed(
            '[[ "$(find /home/alice/ -name user-activation-ran.\\* | wc -l)" == %s ]]' % n
        )


    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("/run/current-system/bin/switch-to-configuration test")
    verify_user_activation_run_count(2)
  '';
})