4 initrdLowerdir = pkgs.runCommand "initrd-lowerdir" { } ''
6 echo "initrd" > $out/initrd.txt
8 initrdLowerdir2 = pkgs.runCommand "initrd-lowerdir-2" { } ''
10 echo "initrd2" > $out/initrd2.txt
12 userspaceLowerdir = pkgs.runCommand "userspace-lowerdir" { } ''
14 echo "userspace" > $out/userspace.txt
16 userspaceLowerdir2 = pkgs.runCommand "userspace-lowerdir-2" { } ''
18 echo "userspace2" > $out/userspace2.txt
23 name = "writable-overlays";
25 meta.maintainers = with lib.maintainers; [ nikstur ];
27 nodes.machine = { config, pkgs, ... }: {
28 boot.initrd.systemd.enable = true;
30 virtualisation.fileSystems = {
33 lowerdir = [ initrdLowerdir ];
34 upperdir = "/.rw-initrd-overlay/upper";
35 workdir = "/.rw-initrd-overlay/work";
39 "/userspace-overlay" = {
41 lowerdir = [ userspaceLowerdir ];
42 upperdir = "/.rw-userspace-overlay/upper";
43 workdir = "/.rw-userspace-overlay/work";
46 "/ro-initrd-overlay" = {
53 "/ro-userspace-overlay" = {
63 machine.wait_for_unit("default.target")
65 with subtest("Initrd overlay"):
66 machine.wait_for_file("/initrd-overlay/initrd.txt", 5)
67 machine.succeed("touch /initrd-overlay/writable.txt")
68 machine.succeed("findmnt --kernel --types overlay /initrd-overlay")
70 with subtest("Userspace overlay"):
71 machine.wait_for_file("/userspace-overlay/userspace.txt", 5)
72 machine.succeed("touch /userspace-overlay/writable.txt")
73 machine.succeed("findmnt --kernel --types overlay /userspace-overlay")
75 with subtest("Read only initrd overlay"):
76 machine.wait_for_file("/ro-initrd-overlay/initrd.txt", 5)
77 machine.wait_for_file("/ro-initrd-overlay/initrd2.txt", 5)
78 machine.fail("touch /ro-initrd-overlay/not-writable.txt")
79 machine.succeed("findmnt --kernel --types overlay /ro-initrd-overlay")
81 with subtest("Read only userspace overlay"):
82 machine.wait_for_file("/ro-userspace-overlay/userspace.txt", 5)
83 machine.wait_for_file("/ro-userspace-overlay/userspace2.txt", 5)
84 machine.fail("touch /ro-userspace-overlay/not-writable.txt")
85 machine.succeed("findmnt --kernel --types overlay /ro-userspace-overlay")