at master 6.0 kB view raw
1# Miscellaneous small tests that don't warrant their own VM run. 2 3{ lib, pkgs, ... }: 4let 5 foo = pkgs.writeText "foo" "Hello World"; 6in 7{ 8 name = "misc"; 9 meta.maintainers = with lib.maintainers; [ eelco ]; 10 11 nodes.machine = 12 { lib, ... }: 13 { 14 swapDevices = lib.mkOverride 0 [ 15 { 16 device = "/root/swapfile"; 17 size = 128; 18 } 19 ]; 20 environment.variables.EDITOR = lib.mkOverride 0 "emacs"; 21 systemd.tmpfiles.rules = [ "d /tmp 1777 root root 10d" ]; 22 systemd.tmpfiles.settings."10-test"."/tmp/somefile".d = { }; 23 virtualisation.fileSystems = { 24 "/tmp2" = { 25 fsType = "tmpfs"; 26 options = [ 27 "mode=1777" 28 "noauto" 29 ]; 30 }; 31 # Tests https://discourse.nixos.org/t/how-to-make-a-derivations-executables-have-the-s-permission/8555 32 "/user-mount/point" = { 33 device = "/user-mount/source"; 34 fsType = "none"; 35 options = [ 36 "bind" 37 "rw" 38 "user" 39 "noauto" 40 ]; 41 }; 42 "/user-mount/denied-point" = { 43 device = "/user-mount/denied-source"; 44 fsType = "none"; 45 options = [ 46 "bind" 47 "rw" 48 "noauto" 49 ]; 50 }; 51 }; 52 systemd.automounts = lib.singleton { 53 wantedBy = [ "multi-user.target" ]; 54 where = "/tmp2"; 55 }; 56 users.users.sybil = { 57 isNormalUser = true; 58 group = "wheel"; 59 }; 60 users.users.alice = { 61 isNormalUser = true; 62 }; 63 security.sudo = { 64 enable = true; 65 wheelNeedsPassword = false; 66 }; 67 boot.kernel.sysctl."vm.swappiness" = 1; 68 boot.kernelParams = [ "vsyscall=emulate" ]; 69 system.extraDependencies = [ foo ]; 70 }; 71 72 testScript = '' 73 with subtest("nixos-version"): 74 machine.succeed("[ `nixos-version | wc -w` = 2 ]") 75 76 with subtest("nixos-rebuild"): 77 assert "NixOS module" in machine.succeed("nixos-rebuild --help") 78 79 with subtest("Sanity check for uid/gid assignment"): 80 assert "4" == machine.succeed("id -u messagebus").strip() 81 assert "4" == machine.succeed("id -g messagebus").strip() 82 assert "users:x:100:" == machine.succeed("getent group users").strip() 83 84 with subtest("Regression test for GMP aborts on QEMU."): 85 machine.succeed("expr 1 + 2") 86 87 with subtest("the swap file got created"): 88 machine.wait_for_unit("root-swapfile.swap") 89 machine.succeed("ls -l /root/swapfile | grep 134217728") 90 91 with subtest("whether kernel.poweroff_cmd is set"): 92 machine.succeed('[ -x "$(cat /proc/sys/kernel/poweroff_cmd)" ]') 93 94 with subtest("whether the io cgroupv2 controller is properly enabled"): 95 machine.succeed("grep -q '\\bio\\b' /sys/fs/cgroup/cgroup.controllers") 96 97 with subtest("whether we have a reboot record in wtmp"): 98 machine.shutdown 99 machine.wait_for_unit("multi-user.target") 100 machine.succeed("last | grep reboot >&2") 101 102 with subtest("whether we can override environment variables"): 103 machine.succeed('[ "$EDITOR" = emacs ]') 104 105 with subtest("whether hostname (and by extension nss_myhostname) works"): 106 assert "machine" == machine.succeed("hostname").strip() 107 assert "machine" == machine.succeed("hostname -s").strip() 108 109 with subtest("whether systemd-udevd automatically loads modules for our hardware"): 110 machine.succeed("systemctl start systemd-udev-settle.service") 111 machine.wait_for_unit("systemd-udev-settle.service") 112 assert "mousedev" in machine.succeed("lsmod") 113 114 with subtest("whether systemd-tmpfiles-clean works"): 115 machine.succeed( 116 "touch /tmp/foo", "systemctl start systemd-tmpfiles-clean", "[ -e /tmp/foo ]" 117 ) 118 # move into the future 119 machine.succeed( 120 'date -s "@$(($(date +%s) + 1000000))"', 121 "systemctl start systemd-tmpfiles-clean", 122 ) 123 machine.fail("[ -e /tmp/foo ]") 124 125 with subtest("whether systemd-tmpfiles settings works"): 126 machine.succeed("[ -e /tmp/somefile ]") 127 128 with subtest("/etc/mtab"): 129 assert "/proc/mounts" == machine.succeed("readlink --no-newline /etc/mtab") 130 131 with subtest("whether automounting works"): 132 machine.fail("grep '/tmp2 tmpfs' /proc/mounts") 133 machine.succeed("touch /tmp2/x") 134 machine.succeed("grep '/tmp2 tmpfs' /proc/mounts") 135 136 with subtest( 137 "Whether mounting by a user is possible with the `user` option in fstab (#95444)" 138 ): 139 machine.succeed("mkdir -p /user-mount/source") 140 machine.succeed("touch /user-mount/source/file") 141 machine.succeed("chmod -R a+Xr /user-mount/source") 142 machine.succeed("mkdir /user-mount/point") 143 machine.succeed("chown alice:users /user-mount/point") 144 machine.succeed("su - alice -c 'mount /user-mount/point'") 145 machine.succeed("su - alice -c 'ls /user-mount/point/file'") 146 with subtest( 147 "Whether mounting by a user is denied without the `user` option in fstab" 148 ): 149 machine.succeed("mkdir -p /user-mount/denied-source") 150 machine.succeed("touch /user-mount/denied-source/file") 151 machine.succeed("chmod -R a+Xr /user-mount/denied-source") 152 machine.succeed("mkdir /user-mount/denied-point") 153 machine.succeed("chown alice:users /user-mount/denied-point") 154 machine.fail("su - alice -c 'mount /user-mount/denied-point'") 155 156 with subtest("shell-vars"): 157 machine.succeed('[ -n "$NIX_PATH" ]') 158 159 with subtest("Test sysctl"): 160 machine.wait_for_unit("systemd-sysctl.service") 161 assert "1" == machine.succeed("sysctl -ne vm.swappiness").strip() 162 machine.execute("sysctl vm.swappiness=60") 163 assert "60" == machine.succeed("sysctl -ne vm.swappiness").strip() 164 165 with subtest("Test boot parameters"): 166 assert "vsyscall=emulate" in machine.succeed("cat /proc/cmdline") 167 ''; 168}