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;
29 boot.initrd.availableKernelModules = [ "overlay" ];
31 virtualisation.fileSystems = {
34 lowerdir = [ initrdLowerdir ];
35 upperdir = "/.rw-initrd-overlay/upper";
36 workdir = "/.rw-initrd-overlay/work";
40 "/userspace-overlay" = {
42 lowerdir = [ userspaceLowerdir ];
43 upperdir = "/.rw-userspace-overlay/upper";
44 workdir = "/.rw-userspace-overlay/work";
47 "/ro-initrd-overlay" = {
54 "/ro-userspace-overlay" = {
64 machine.wait_for_unit("default.target")
66 with subtest("Initrd overlay"):
67 machine.wait_for_file("/initrd-overlay/initrd.txt", 5)
68 machine.succeed("touch /initrd-overlay/writable.txt")
69 machine.succeed("findmnt --kernel --types overlay /initrd-overlay")
71 with subtest("Userspace overlay"):
72 machine.wait_for_file("/userspace-overlay/userspace.txt", 5)
73 machine.succeed("touch /userspace-overlay/writable.txt")
74 machine.succeed("findmnt --kernel --types overlay /userspace-overlay")
76 with subtest("Read only initrd overlay"):
77 machine.wait_for_file("/ro-initrd-overlay/initrd.txt", 5)
78 machine.wait_for_file("/ro-initrd-overlay/initrd2.txt", 5)
79 machine.fail("touch /ro-initrd-overlay/not-writable.txt")
80 machine.succeed("findmnt --kernel --types overlay /ro-initrd-overlay")
82 with subtest("Read only userspace overlay"):
83 machine.wait_for_file("/ro-userspace-overlay/userspace.txt", 5)
84 machine.wait_for_file("/ro-userspace-overlay/userspace2.txt", 5)
85 machine.fail("touch /ro-userspace-overlay/not-writable.txt")
86 machine.succeed("findmnt --kernel --types overlay /ro-userspace-overlay")