4 name = "activation-etc-overlay-immutable";
6 meta.maintainers = with lib.maintainers; [ nikstur ];
11 system.etc.overlay.enable = true;
12 system.etc.overlay.mutable = false;
15 systemd.sysusers.enable = true;
16 users.mutableUsers = false;
17 boot.initrd.systemd.enable = true;
18 boot.kernelPackages = pkgs.linuxPackages_latest;
19 time.timeZone = "Utc";
21 # The standard resolvconf service tries to write to /etc and crashes,
22 # which makes nixos-rebuild exit uncleanly when switching into the new generation
23 services.resolved.enable = true;
26 "mountpoint/.keep".text = "keep";
27 "filemount".text = "keep";
30 specialisation.new-generation.configuration = {
31 environment.etc."newgen".text = "newgen";
33 specialisation.newer-generation.configuration = {
34 environment.etc."newergen".text = "newergen";
40 newergen = machine.succeed("realpath /run/current-system/specialisation/newer-generation/bin/switch-to-configuration").rstrip()
42 with subtest("/run/nixos-etc-metadata/ is mounted"):
43 print(machine.succeed("mountpoint /run/nixos-etc-metadata"))
45 with subtest("No temporary files leaked into stage 2"):
46 machine.succeed("[ ! -e /etc-metadata-image ]")
47 machine.succeed("[ ! -e /etc-basedir ]")
49 with subtest("/etc is mounted as an overlay"):
50 machine.succeed("findmnt --kernel --type overlay /etc")
52 with subtest("direct symlinks point to the target without indirection"):
53 assert machine.succeed("readlink -n /etc/localtime") == "/etc/zoneinfo/Utc"
55 with subtest("/etc/mtab points to the right file"):
56 assert "/proc/mounts" == machine.succeed("readlink --no-newline /etc/mtab")
58 with subtest("Correct mode on the source password files"):
59 assert machine.succeed("stat -c '%a' /var/lib/nixos/etc/passwd") == "644\n"
60 assert machine.succeed("stat -c '%a' /var/lib/nixos/etc/group") == "644\n"
61 assert machine.succeed("stat -c '%a' /var/lib/nixos/etc/shadow") == "0\n"
62 assert machine.succeed("stat -c '%a' /var/lib/nixos/etc/gshadow") == "0\n"
64 with subtest("Password files are symlinks to /var/lib/nixos/etc"):
65 assert machine.succeed("readlink -f /etc/passwd") == "/var/lib/nixos/etc/passwd\n"
66 assert machine.succeed("readlink -f /etc/group") == "/var/lib/nixos/etc/group\n"
67 assert machine.succeed("readlink -f /etc/shadow") == "/var/lib/nixos/etc/shadow\n"
68 assert machine.succeed("readlink -f /etc/gshadow") == "/var/lib/nixos/etc/gshadow\n"
70 with subtest("switching to the same generation"):
71 machine.succeed("/run/current-system/bin/switch-to-configuration test")
73 with subtest("the initrd didn't get rebuilt"):
74 machine.succeed("test /run/current-system/initrd -ef /run/current-system/specialisation/new-generation/initrd")
76 with subtest("switching to a new generation"):
77 machine.fail("stat /etc/newgen")
79 machine.succeed("mount -t tmpfs tmpfs /etc/mountpoint")
80 machine.succeed("touch /etc/mountpoint/extra-file")
81 machine.succeed("mount --bind /dev/null /etc/filemount")
83 machine.succeed("/run/current-system/specialisation/new-generation/bin/switch-to-configuration switch")
85 assert machine.succeed("cat /etc/newgen") == "newgen"
87 print(machine.succeed("findmnt /etc/mountpoint"))
88 print(machine.succeed("ls /etc/mountpoint"))
89 print(machine.succeed("stat /etc/mountpoint/extra-file"))
90 print(machine.succeed("findmnt /etc/filemount"))
92 machine.succeed(f"{newergen} switch")
94 tmpMounts = machine.succeed("find /run -maxdepth 1 -type d -regex '/run/nixos-etc\\..*'").rstrip()
96 metaMounts = machine.succeed("find /run -maxdepth 1 -type d -regex '/run/nixos-etc-metadata.*'").rstrip()
99 numOfTmpMounts = len(tmpMounts.splitlines())
100 numOfMetaMounts = len(metaMounts.splitlines())
101 assert numOfTmpMounts == 0, f"Found {numOfTmpMounts} remaining tmpmounts"
102 assert numOfMetaMounts == 1, f"Found {numOfMetaMounts} remaining metamounts"