1 # Miscellaneous small tests that don't warrant their own VM run.
3 import ./make-test-python.nix ({ pkgs, ...} : let
4 foo = pkgs.writeText "foo" "Hello World";
7 meta = with pkgs.lib.maintainers; {
8 maintainers = [ eelco ];
14 { swapDevices = mkOverride 0
15 [ { device = "/root/swapfile"; size = 128; } ];
16 environment.variables.EDITOR = mkOverride 0 "emacs";
17 documentation.nixos.enable = mkOverride 0 true;
18 systemd.tmpfiles.rules = [ "d /tmp 1777 root root 10d" ];
19 virtualisation.fileSystems = { "/tmp2" =
21 options = [ "mode=1777" "noauto" ];
23 # Tests https://discourse.nixos.org/t/how-to-make-a-derivations-executables-have-the-s-permission/8555
24 "/user-mount/point" = {
25 device = "/user-mount/source";
27 options = [ "bind" "rw" "user" "noauto" ];
29 "/user-mount/denied-point" = {
30 device = "/user-mount/denied-source";
32 options = [ "bind" "rw" "noauto" ];
35 systemd.automounts = singleton
36 { wantedBy = [ "multi-user.target" ];
39 users.users.sybil = { isNormalUser = true; group = "wheel"; };
40 users.users.alice = { isNormalUser = true; };
41 security.sudo = { enable = true; wheelNeedsPassword = false; };
42 boot.kernel.sysctl."vm.swappiness" = 1;
43 boot.kernelParams = [ "vsyscall=emulate" ];
44 system.extraDependencies = [ foo ];
52 def get_path_info(path):
53 result = machine.succeed(f"nix --option experimental-features nix-command path-info --json {path}")
54 parsed = json.loads(result)
58 with subtest("nix-db"):
59 info = get_path_info("${foo}")
64 != "sha256-BdMdnb/0eWy3EddjE83rdgzWWpQjfWPAj3zDIFMD3Ck="
66 raise Exception("narHash not set")
68 if info[0]["narSize"] != 128:
69 raise Exception("narSize not set")
71 with subtest("nixos-version"):
72 machine.succeed("[ `nixos-version | wc -w` = 2 ]")
74 with subtest("nixos-rebuild"):
75 assert "NixOS module" in machine.succeed("nixos-rebuild --help")
77 with subtest("Sanity check for uid/gid assignment"):
78 assert "4" == machine.succeed("id -u messagebus").strip()
79 assert "4" == machine.succeed("id -g messagebus").strip()
80 assert "users:x:100:" == machine.succeed("getent group users").strip()
82 with subtest("Regression test for GMP aborts on QEMU."):
83 machine.succeed("expr 1 + 2")
85 with subtest("the swap file got created"):
86 machine.wait_for_unit("root-swapfile.swap")
87 machine.succeed("ls -l /root/swapfile | grep 134217728")
89 with subtest("whether kernel.poweroff_cmd is set"):
90 machine.succeed('[ -x "$(cat /proc/sys/kernel/poweroff_cmd)" ]')
92 with subtest("whether the io cgroupv2 controller is properly enabled"):
93 machine.succeed("grep -q '\\bio\\b' /sys/fs/cgroup/cgroup.controllers")
95 with subtest("whether we have a reboot record in wtmp"):
97 machine.wait_for_unit("multi-user.target")
98 machine.succeed("last | grep reboot >&2")
100 with subtest("whether we can override environment variables"):
101 machine.succeed('[ "$EDITOR" = emacs ]')
103 with subtest("whether hostname (and by extension nss_myhostname) works"):
104 assert "machine" == machine.succeed("hostname").strip()
105 assert "machine" == machine.succeed("hostname -s").strip()
107 with subtest("whether systemd-udevd automatically loads modules for our hardware"):
108 machine.succeed("systemctl start systemd-udev-settle.service")
109 machine.wait_for_unit("systemd-udev-settle.service")
110 assert "mousedev" in machine.succeed("lsmod")
112 with subtest("whether systemd-tmpfiles-clean works"):
114 "touch /tmp/foo", "systemctl start systemd-tmpfiles-clean", "[ -e /tmp/foo ]"
116 # move into the future
118 'date -s "@$(($(date +%s) + 1000000))"',
119 "systemctl start systemd-tmpfiles-clean",
121 machine.fail("[ -e /tmp/foo ]")
123 with subtest("whether automounting works"):
124 machine.fail("grep '/tmp2 tmpfs' /proc/mounts")
125 machine.succeed("touch /tmp2/x")
126 machine.succeed("grep '/tmp2 tmpfs' /proc/mounts")
129 "Whether mounting by a user is possible with the `user` option in fstab (#95444)"
131 machine.succeed("mkdir -p /user-mount/source")
132 machine.succeed("touch /user-mount/source/file")
133 machine.succeed("chmod -R a+Xr /user-mount/source")
134 machine.succeed("mkdir /user-mount/point")
135 machine.succeed("chown alice:users /user-mount/point")
136 machine.succeed("su - alice -c 'mount /user-mount/point'")
137 machine.succeed("su - alice -c 'ls /user-mount/point/file'")
139 "Whether mounting by a user is denied without the `user` option in fstab"
141 machine.succeed("mkdir -p /user-mount/denied-source")
142 machine.succeed("touch /user-mount/denied-source/file")
143 machine.succeed("chmod -R a+Xr /user-mount/denied-source")
144 machine.succeed("mkdir /user-mount/denied-point")
145 machine.succeed("chown alice:users /user-mount/denied-point")
146 machine.fail("su - alice -c 'mount /user-mount/denied-point'")
148 with subtest("shell-vars"):
149 machine.succeed('[ -n "$NIX_PATH" ]')
151 with subtest("nix-db"):
152 machine.succeed("nix-store -qR /run/current-system | grep nixos-")
154 with subtest("Test sysctl"):
155 machine.wait_for_unit("systemd-sysctl.service")
156 assert "1" == machine.succeed("sysctl -ne vm.swappiness").strip()
157 machine.execute("sysctl vm.swappiness=60")
158 assert "60" == machine.succeed("sysctl -ne vm.swappiness").strip()
160 with subtest("Test boot parameters"):
161 assert "vsyscall=emulate" in machine.succeed("cat /proc/cmdline")