4 rootPassword = "$y$j9T$p6OI0WN7.rSfZBOijjRdR.$xUOA2MTcB48ac.9Oc5fz8cxwLv1mMqabnn333iOzSA6";
5 sysuserPassword = "hello";
6 newSysuserPassword = "$y$j9T$p6OI0WN7.rSfZBOijjRdR.$xUOA2MTcB48ac.9Oc5fz8cxwLv1mMqabnn333iOzSA6";
11 name = "activation-sysusers-mutable";
13 meta.maintainers = with lib.maintainers; [ nikstur ];
15 nodes.machine = { pkgs, ... }: {
16 systemd.sysusers.enable = true;
17 users.mutableUsers = true;
20 system.etc.overlay.enable = true;
21 boot.initrd.systemd.enable = true;
22 boot.kernelPackages = pkgs.linuxPackages_latest;
24 # Override the empty root password set by the test instrumentation
25 users.users.root.hashedPasswordFile = lib.mkForce null;
26 users.users.root.initialHashedPassword = rootPassword;
27 users.users.sysuser = {
31 initialPassword = sysuserPassword;
34 specialisation.new-generation.configuration = {
35 users.users.new-sysuser = {
38 home = "/new-sysuser";
39 initialHashedPassword = newSysuserPassword;
45 machine.wait_for_unit("systemd-sysusers.service")
47 with subtest("systemd-sysusers.service contains the credentials"):
48 sysusers_service = machine.succeed("systemctl cat systemd-sysusers.service")
49 print(sysusers_service)
50 assert "SetCredential=passwd.plaintext-password.sysuser:${sysuserPassword}" in sysusers_service
52 with subtest("Correct mode on the password files"):
53 assert machine.succeed("stat -c '%a' /etc/passwd") == "644\n"
54 assert machine.succeed("stat -c '%a' /etc/group") == "644\n"
55 assert machine.succeed("stat -c '%a' /etc/shadow") == "0\n"
56 assert machine.succeed("stat -c '%a' /etc/gshadow") == "0\n"
58 with subtest("root user has correct password"):
59 print(machine.succeed("getent passwd root"))
60 assert "${rootPassword}" in machine.succeed("getent shadow root"), "root user password is not correct"
62 with subtest("sysuser user is created"):
63 print(machine.succeed("getent passwd sysuser"))
64 assert machine.succeed("stat -c '%U' /sysuser") == "sysuser\n"
66 with subtest("Manually add new user"):
67 machine.succeed("useradd manual-sysuser")
70 machine.succeed("/run/current-system/specialisation/new-generation/bin/switch-to-configuration switch")
73 with subtest("new-sysuser user is created after switching to new generation"):
74 print(machine.succeed("getent passwd new-sysuser"))
75 assert machine.succeed("stat -c '%U' /new-sysuser") == "new-sysuser\n"
76 assert "${newSysuserPassword}" in machine.succeed("getent shadow new-sysuser"), "new-sysuser user password is not correct"