at 22.05-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 --option experimental-features nix-command 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 print(info) 61 62 if ( 63 info[0]["narHash"] 64 != "sha256-BdMdnb/0eWy3EddjE83rdgzWWpQjfWPAj3zDIFMD3Ck=" 65 ): 66 raise Exception("narHash not set") 67 68 if info[0]["narSize"] != 128: 69 raise Exception("narSize not set") 70 71 with subtest("nixos-version"): 72 machine.succeed("[ `nixos-version | wc -w` = 2 ]") 73 74 with subtest("nixos-rebuild"): 75 assert "NixOS module" in machine.succeed("nixos-rebuild --help") 76 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() 81 82 with subtest("Regression test for GMP aborts on QEMU."): 83 machine.succeed("expr 1 + 2") 84 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") 88 89 with subtest("whether kernel.poweroff_cmd is set"): 90 machine.succeed('[ -x "$(cat /proc/sys/kernel/poweroff_cmd)" ]') 91 92 with subtest("whether the io cgroupv2 controller is properly enabled"): 93 machine.succeed("grep -q '\\bio\\b' /sys/fs/cgroup/cgroup.controllers") 94 95 with subtest("whether we have a reboot record in wtmp"): 96 machine.shutdown 97 machine.wait_for_unit("multi-user.target") 98 machine.succeed("last | grep reboot >&2") 99 100 with subtest("whether we can override environment variables"): 101 machine.succeed('[ "$EDITOR" = emacs ]') 102 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() 106 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") 111 112 with subtest("whether systemd-tmpfiles-clean works"): 113 machine.succeed( 114 "touch /tmp/foo", "systemctl start systemd-tmpfiles-clean", "[ -e /tmp/foo ]" 115 ) 116 # move into the future 117 machine.succeed( 118 'date -s "@$(($(date +%s) + 1000000))"', 119 "systemctl start systemd-tmpfiles-clean", 120 ) 121 machine.fail("[ -e /tmp/foo ]") 122 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") 127 128 with subtest( 129 "Whether mounting by a user is possible with the `user` option in fstab (#95444)" 130 ): 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'") 138 with subtest( 139 "Whether mounting by a user is denied without the `user` option in fstab" 140 ): 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'") 147 148 with subtest("shell-vars"): 149 machine.succeed('[ -n "$NIX_PATH" ]') 150 151 with subtest("nix-db"): 152 machine.succeed("nix-store -qR /run/current-system | grep nixos-") 153 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() 159 160 with subtest("Test boot parameters"): 161 assert "vsyscall=emulate" in machine.succeed("cat /proc/cmdline") 162 ''; 163})