at 21.11-pre 6.4 kB view raw
1# Miscellaneous small tests that don't warrant their own VM run. 2 3import ./make-test-python.nix ({ pkgs, ...} : rec { 4 name = "misc"; 5 meta = with pkgs.lib.maintainers; { 6 maintainers = [ eelco ]; 7 }; 8 9 foo = pkgs.writeText "foo" "Hello World"; 10 11 machine = 12 { lib, ... }: 13 with lib; 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" = 20 { fsType = "tmpfs"; 21 options = [ "mode=1777" "noauto" ]; 22 }; 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"; 26 fsType = "none"; 27 options = [ "bind" "rw" "user" "noauto" ]; 28 }; 29 "/user-mount/denied-point" = { 30 device = "/user-mount/denied-source"; 31 fsType = "none"; 32 options = [ "bind" "rw" "noauto" ]; 33 }; 34 }; 35 systemd.automounts = singleton 36 { wantedBy = [ "multi-user.target" ]; 37 where = "/tmp2"; 38 }; 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 ]; 45 }; 46 47 testScript = 48 '' 49 import json 50 51 52 def get_path_info(path): 53 result = machine.succeed(f"nix path-info --json {path}") 54 parsed = json.loads(result) 55 return parsed 56 57 58 with subtest("nix-db"): 59 info = get_path_info("${foo}") 60 61 if ( 62 info[0]["narHash"] 63 != "sha256:0afw0d9j1hvwiz066z93jiddc33nxg6i6qyp26vnqyglpyfivlq5" 64 ): 65 raise Exception("narHash not set") 66 67 if info[0]["narSize"] != 128: 68 raise Exception("narSize not set") 69 70 with subtest("nixos-version"): 71 machine.succeed("[ `nixos-version | wc -w` = 2 ]") 72 73 with subtest("nixos-rebuild"): 74 assert "NixOS module" in machine.succeed("nixos-rebuild --help") 75 76 with subtest("Sanity check for uid/gid assignment"): 77 assert "4" == machine.succeed("id -u messagebus").strip() 78 assert "4" == machine.succeed("id -g messagebus").strip() 79 assert "users:x:100:" == machine.succeed("getent group users").strip() 80 81 with subtest("Regression test for GMP aborts on QEMU."): 82 machine.succeed("expr 1 + 2") 83 84 with subtest("the swap file got created"): 85 machine.wait_for_unit("root-swapfile.swap") 86 machine.succeed("ls -l /root/swapfile | grep 134217728") 87 88 with subtest("whether kernel.poweroff_cmd is set"): 89 machine.succeed('[ -x "$(cat /proc/sys/kernel/poweroff_cmd)" ]') 90 91 with subtest("whether the io cgroupv2 controller is properly enabled"): 92 machine.succeed("grep -q '\\bio\\b' /sys/fs/cgroup/cgroup.controllers") 93 94 with subtest("whether we have a reboot record in wtmp"): 95 machine.shutdown 96 machine.wait_for_unit("multi-user.target") 97 machine.succeed("last | grep reboot >&2") 98 99 with subtest("whether we can override environment variables"): 100 machine.succeed('[ "$EDITOR" = emacs ]') 101 102 with subtest("whether hostname (and by extension nss_myhostname) works"): 103 assert "machine" == machine.succeed("hostname").strip() 104 assert "machine" == machine.succeed("hostname -s").strip() 105 106 with subtest("whether systemd-udevd automatically loads modules for our hardware"): 107 machine.succeed("systemctl start systemd-udev-settle.service") 108 machine.wait_for_unit("systemd-udev-settle.service") 109 assert "mousedev" in machine.succeed("lsmod") 110 111 with subtest("whether systemd-tmpfiles-clean works"): 112 machine.succeed( 113 "touch /tmp/foo", "systemctl start systemd-tmpfiles-clean", "[ -e /tmp/foo ]" 114 ) 115 # move into the future 116 machine.succeed( 117 'date -s "@$(($(date +%s) + 1000000))"', 118 "systemctl start systemd-tmpfiles-clean", 119 ) 120 machine.fail("[ -e /tmp/foo ]") 121 122 with subtest("whether automounting works"): 123 machine.fail("grep '/tmp2 tmpfs' /proc/mounts") 124 machine.succeed("touch /tmp2/x") 125 machine.succeed("grep '/tmp2 tmpfs' /proc/mounts") 126 127 with subtest( 128 "Whether mounting by a user is possible with the `user` option in fstab (#95444)" 129 ): 130 machine.succeed("mkdir -p /user-mount/source") 131 machine.succeed("touch /user-mount/source/file") 132 machine.succeed("chmod -R a+Xr /user-mount/source") 133 machine.succeed("mkdir /user-mount/point") 134 machine.succeed("chown alice:users /user-mount/point") 135 machine.succeed("su - alice -c 'mount /user-mount/point'") 136 machine.succeed("su - alice -c 'ls /user-mount/point/file'") 137 with subtest( 138 "Whether mounting by a user is denied without the `user` option in fstab" 139 ): 140 machine.succeed("mkdir -p /user-mount/denied-source") 141 machine.succeed("touch /user-mount/denied-source/file") 142 machine.succeed("chmod -R a+Xr /user-mount/denied-source") 143 machine.succeed("mkdir /user-mount/denied-point") 144 machine.succeed("chown alice:users /user-mount/denied-point") 145 machine.fail("su - alice -c 'mount /user-mount/denied-point'") 146 147 with subtest("shell-vars"): 148 machine.succeed('[ -n "$NIX_PATH" ]') 149 150 with subtest("nix-db"): 151 machine.succeed("nix-store -qR /run/current-system | grep nixos-") 152 153 with subtest("Test sysctl"): 154 machine.wait_for_unit("systemd-sysctl.service") 155 assert "1" == machine.succeed("sysctl -ne vm.swappiness").strip() 156 machine.execute("sysctl vm.swappiness=60") 157 assert "60" == machine.succeed("sysctl -ne vm.swappiness").strip() 158 159 with subtest("Test boot parameters"): 160 assert "vsyscall=emulate" in machine.succeed("cat /proc/cmdline") 161 ''; 162})