1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "containers-tmpfs";
4 maintainers = with lib.maintainers; [ patryk27 ];
9 { imports = [ ../modules/installer/cd-dvd/channel.nix ];
10 virtualisation.writableStore = true;
16 # Mount var as a tmpfs
19 # Add a nested mount inside a tmpfs
22 # Add a tmpfs on a path that does not exist
28 virtualisation.additionalPaths = [ pkgs.stdenv ];
32 machine.wait_for_unit("default.target")
33 assert "tmpfs" in machine.succeed("nixos-container list")
35 with subtest("tmpfs container is up"):
36 assert "up" in machine.succeed("nixos-container status tmpfs")
39 def tmpfs_cmd(command):
40 return f"nixos-container run tmpfs -- {command} 2>/dev/null"
43 with subtest("/var is mounted as a tmpfs"):
44 machine.succeed(tmpfs_cmd("mountpoint -q /var"))
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")
50 machine.succeed(tmpfs_cmd("mountpoint -q /var/log"))
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")
56 machine.succeed(tmpfs_cmd("mountpoint -q /some/random/path"))
59 "files created in the container in a non-tmpfs directory are visible on the host."
61 # This establishes legitimacy for the following tests
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",
69 "/some/random/path is writable and that files created there are not "
70 + "in the hosts container dir but in the tmpfs"
73 tmpfs_cmd("touch /some/random/path/test.file"),
74 tmpfs_cmd("test -e /some/random/path/test.file"),
76 machine.fail("test -e /var/lib/nixos-containers/tmpfs/some/random/path/test.file")
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"
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",
88 machine.fail(tmpfs_cmd("ls -l /var | grep -q test.file"))