1 # Miscellaneous small tests that don't warrant their own VM run.
3 import ./make-test-python.nix ({ lib, pkgs, ...} : let
4 foo = pkgs.writeText "foo" "Hello World";
7 meta.maintainers = with lib.maintainers; [ eelco ];
11 { swapDevices = lib.mkOverride 0
12 [ { device = "/root/swapfile"; size = 128; } ];
13 environment.variables.EDITOR = lib.mkOverride 0 "emacs";
14 documentation.nixos.enable = lib.mkOverride 0 true;
15 systemd.tmpfiles.rules = [ "d /tmp 1777 root root 10d" ];
16 systemd.tmpfiles.settings."10-test"."/tmp/somefile".d = {};
17 virtualisation.fileSystems = { "/tmp2" =
19 options = [ "mode=1777" "noauto" ];
21 # Tests https://discourse.nixos.org/t/how-to-make-a-derivations-executables-have-the-s-permission/8555
22 "/user-mount/point" = {
23 device = "/user-mount/source";
25 options = [ "bind" "rw" "user" "noauto" ];
27 "/user-mount/denied-point" = {
28 device = "/user-mount/denied-source";
30 options = [ "bind" "rw" "noauto" ];
33 systemd.automounts = lib.singleton
34 { wantedBy = [ "multi-user.target" ];
37 users.users.sybil = { isNormalUser = true; group = "wheel"; };
38 users.users.alice = { isNormalUser = true; };
39 security.sudo = { enable = true; wheelNeedsPassword = false; };
40 boot.kernel.sysctl."vm.swappiness" = 1;
41 boot.kernelParams = [ "vsyscall=emulate" ];
42 system.extraDependencies = [ foo ];
47 with subtest("nixos-version"):
48 machine.succeed("[ `nixos-version | wc -w` = 2 ]")
50 with subtest("nixos-rebuild"):
51 assert "NixOS module" in machine.succeed("nixos-rebuild --help")
53 with subtest("Sanity check for uid/gid assignment"):
54 assert "4" == machine.succeed("id -u messagebus").strip()
55 assert "4" == machine.succeed("id -g messagebus").strip()
56 assert "users:x:100:" == machine.succeed("getent group users").strip()
58 with subtest("Regression test for GMP aborts on QEMU."):
59 machine.succeed("expr 1 + 2")
61 with subtest("the swap file got created"):
62 machine.wait_for_unit("root-swapfile.swap")
63 machine.succeed("ls -l /root/swapfile | grep 134217728")
65 with subtest("whether kernel.poweroff_cmd is set"):
66 machine.succeed('[ -x "$(cat /proc/sys/kernel/poweroff_cmd)" ]')
68 with subtest("whether the io cgroupv2 controller is properly enabled"):
69 machine.succeed("grep -q '\\bio\\b' /sys/fs/cgroup/cgroup.controllers")
71 with subtest("whether we have a reboot record in wtmp"):
73 machine.wait_for_unit("multi-user.target")
74 machine.succeed("last | grep reboot >&2")
76 with subtest("whether we can override environment variables"):
77 machine.succeed('[ "$EDITOR" = emacs ]')
79 with subtest("whether hostname (and by extension nss_myhostname) works"):
80 assert "machine" == machine.succeed("hostname").strip()
81 assert "machine" == machine.succeed("hostname -s").strip()
83 with subtest("whether systemd-udevd automatically loads modules for our hardware"):
84 machine.succeed("systemctl start systemd-udev-settle.service")
85 machine.wait_for_unit("systemd-udev-settle.service")
86 assert "mousedev" in machine.succeed("lsmod")
88 with subtest("whether systemd-tmpfiles-clean works"):
90 "touch /tmp/foo", "systemctl start systemd-tmpfiles-clean", "[ -e /tmp/foo ]"
92 # move into the future
94 'date -s "@$(($(date +%s) + 1000000))"',
95 "systemctl start systemd-tmpfiles-clean",
97 machine.fail("[ -e /tmp/foo ]")
99 with subtest("whether systemd-tmpfiles settings works"):
100 machine.succeed("[ -e /tmp/somefile ]")
102 with subtest("/etc/mtab"):
103 assert "/proc/mounts" == machine.succeed("readlink --no-newline /etc/mtab")
105 with subtest("whether automounting works"):
106 machine.fail("grep '/tmp2 tmpfs' /proc/mounts")
107 machine.succeed("touch /tmp2/x")
108 machine.succeed("grep '/tmp2 tmpfs' /proc/mounts")
111 "Whether mounting by a user is possible with the `user` option in fstab (#95444)"
113 machine.succeed("mkdir -p /user-mount/source")
114 machine.succeed("touch /user-mount/source/file")
115 machine.succeed("chmod -R a+Xr /user-mount/source")
116 machine.succeed("mkdir /user-mount/point")
117 machine.succeed("chown alice:users /user-mount/point")
118 machine.succeed("su - alice -c 'mount /user-mount/point'")
119 machine.succeed("su - alice -c 'ls /user-mount/point/file'")
121 "Whether mounting by a user is denied without the `user` option in fstab"
123 machine.succeed("mkdir -p /user-mount/denied-source")
124 machine.succeed("touch /user-mount/denied-source/file")
125 machine.succeed("chmod -R a+Xr /user-mount/denied-source")
126 machine.succeed("mkdir /user-mount/denied-point")
127 machine.succeed("chown alice:users /user-mount/denied-point")
128 machine.fail("su - alice -c 'mount /user-mount/denied-point'")
130 with subtest("shell-vars"):
131 machine.succeed('[ -n "$NIX_PATH" ]')
133 with subtest("Test sysctl"):
134 machine.wait_for_unit("systemd-sysctl.service")
135 assert "1" == machine.succeed("sysctl -ne vm.swappiness").strip()
136 machine.execute("sysctl vm.swappiness=60")
137 assert "60" == machine.succeed("sysctl -ne vm.swappiness").strip()
139 with subtest("Test boot parameters"):
140 assert "vsyscall=emulate" in machine.succeed("cat /proc/cmdline")