3 import ./make-test-python.nix ({ pkgs, ...} : {
4 name = "mutable-users";
5 meta = with pkgs.lib.maintainers; {
6 maintainers = [ gleber ];
11 specialisation.immutable.configuration = {
12 users.mutableUsers = false;
15 specialisation.mutable.configuration = {
16 users.mutableUsers = true;
17 users.users.dry-test.isNormalUser = true;
24 machine.wait_for_unit("default.target")
26 # Machine starts in immutable mode. Add a user and test if reactivating
27 # configuration removes the user.
28 with subtest("Machine in immutable mode"):
29 assert "foobar" not in machine.succeed("cat /etc/passwd")
30 machine.succeed("sudo useradd foobar")
31 assert "foobar" in machine.succeed("cat /etc/passwd")
33 "/run/booted-system/specialisation/immutable/bin/switch-to-configuration test"
35 assert "foobar" not in machine.succeed("cat /etc/passwd")
37 # In immutable mode passwd is not wrapped, while in mutable mode it is
39 with subtest("Password is wrapped in mutable mode"):
40 assert "/run/current-system/" in machine.succeed("which passwd")
42 "/run/booted-system/specialisation/mutable/bin/switch-to-configuration test"
44 assert "/run/wrappers/" in machine.succeed("which passwd")
46 with subtest("dry-activation does not change files"):
47 machine.succeed('test -e /home/dry-test') # home was created
48 machine.succeed('rm -rf /home/dry-test')
50 files_to_check = ['/etc/group',
55 '/var/lib/nixos/uid-map',
56 '/var/lib/nixos/gid-map',
57 '/var/lib/nixos/declarative-groups',
58 '/var/lib/nixos/declarative-users'
62 for file in files_to_check:
63 expected_hashes[file] = machine.succeed(f"sha256sum {file}")
64 expected_stats[file] = machine.succeed(f"stat {file}")
66 machine.succeed("/run/booted-system/specialisation/mutable/bin/switch-to-configuration dry-activate")
68 machine.fail('test -e /home/dry-test') # home was not recreated
69 for file in files_to_check:
70 assert machine.succeed(f"sha256sum {file}") == expected_hashes[file]
71 assert machine.succeed(f"stat {file}") == expected_stats[file]