at 23.11-pre 3.1 kB view raw
1import ./make-test-python.nix ({ pkgs, lib, ... }: { 2 name = "containers-tmpfs"; 3 meta = { 4 maintainers = with lib.maintainers; [ patryk27 ]; 5 }; 6 7 nodes.machine = 8 { pkgs, ... }: 9 { imports = [ ../modules/installer/cd-dvd/channel.nix ]; 10 virtualisation.writableStore = true; 11 12 containers.tmpfs = 13 { 14 autoStart = true; 15 tmpfs = [ 16 # Mount var as a tmpfs 17 "/var" 18 19 # Add a nested mount inside a tmpfs 20 "/var/log" 21 22 # Add a tmpfs on a path that does not exist 23 "/some/random/path" 24 ]; 25 config = { }; 26 }; 27 28 virtualisation.additionalPaths = [ pkgs.stdenv ]; 29 }; 30 31 testScript = '' 32 machine.wait_for_unit("default.target") 33 assert "tmpfs" in machine.succeed("nixos-container list") 34 35 with subtest("tmpfs container is up"): 36 assert "up" in machine.succeed("nixos-container status tmpfs") 37 38 39 def tmpfs_cmd(command): 40 return f"nixos-container run tmpfs -- {command} 2>/dev/null" 41 42 43 with subtest("/var is mounted as a tmpfs"): 44 machine.succeed(tmpfs_cmd("mountpoint -q /var")) 45 46 with subtest("/var/log is mounted as a tmpfs"): 47 assert "What: tmpfs" in machine.succeed( 48 tmpfs_cmd("systemctl status var-log.mount --no-pager") 49 ) 50 machine.succeed(tmpfs_cmd("mountpoint -q /var/log")) 51 52 with subtest("/some/random/path is mounted as a tmpfs"): 53 assert "What: tmpfs" in machine.succeed( 54 tmpfs_cmd("systemctl status some-random-path.mount --no-pager") 55 ) 56 machine.succeed(tmpfs_cmd("mountpoint -q /some/random/path")) 57 58 with subtest( 59 "files created in the container in a non-tmpfs directory are visible on the host." 60 ): 61 # This establishes legitimacy for the following tests 62 machine.succeed( 63 tmpfs_cmd("touch /root/test.file"), 64 tmpfs_cmd("ls -l /root | grep -q test.file"), 65 "test -e /var/lib/nixos-containers/tmpfs/root/test.file", 66 ) 67 68 with subtest( 69 "/some/random/path is writable and that files created there are not " 70 + "in the hosts container dir but in the tmpfs" 71 ): 72 machine.succeed( 73 tmpfs_cmd("touch /some/random/path/test.file"), 74 tmpfs_cmd("test -e /some/random/path/test.file"), 75 ) 76 machine.fail("test -e /var/lib/nixos-containers/tmpfs/some/random/path/test.file") 77 78 with subtest( 79 "files created in the hosts container dir in a path where a tmpfs " 80 + "file system has been mounted are not visible to the container as " 81 + "the do not exist in the tmpfs" 82 ): 83 machine.succeed( 84 "touch /var/lib/nixos-containers/tmpfs/var/test.file", 85 "test -e /var/lib/nixos-containers/tmpfs/var/test.file", 86 "ls -l /var/lib/nixos-containers/tmpfs/var/ | grep -q test.file 2>/dev/null", 87 ) 88 machine.fail(tmpfs_cmd("ls -l /var | grep -q test.file")) 89 ''; 90})