1# Miscellaneous small tests that don't warrant their own VM run.
2
3import ./make-test.nix ({ pkgs, ...} : {
4 name = "misc";
5 meta = with pkgs.stdenv.lib.maintainers; {
6 maintainers = [ eelco chaoflow ];
7 };
8
9 machine =
10 { config, lib, pkgs, ... }:
11 with lib;
12 { swapDevices = mkOverride 0
13 [ { device = "/root/swapfile"; size = 128; } ];
14 environment.variables.EDITOR = mkOverride 0 "emacs";
15 services.nixosManual.enable = mkOverride 0 true;
16 systemd.tmpfiles.rules = [ "d /tmp 1777 root root 10d" ];
17 fileSystems = mkVMOverride { "/tmp2" =
18 { fsType = "tmpfs";
19 options = [ "mode=1777" "noauto" ];
20 };
21 };
22 systemd.automounts = singleton
23 { wantedBy = [ "multi-user.target" ];
24 where = "/tmp2";
25 };
26 users.users.sybil = { isNormalUser = true; group = "wheel"; };
27 security.sudo = { enable = true; wheelNeedsPassword = false; };
28 };
29
30 testScript =
31 ''
32 subtest "nixos-version", sub {
33 $machine->succeed("[ `nixos-version | wc -w` = 2 ]");
34 };
35
36 subtest "nixos-rebuild", sub {
37 $machine->succeed("nixos-rebuild --help | grep 'NixOS module' ");
38 };
39
40 # Sanity check for uid/gid assignment.
41 subtest "users-groups", sub {
42 $machine->succeed("[ `id -u messagebus` = 4 ]");
43 $machine->succeed("[ `id -g messagebus` = 4 ]");
44 $machine->succeed("[ `getent group users` = 'users:x:100:' ]");
45 };
46
47 # Regression test for GMP aborts on QEMU.
48 subtest "gmp", sub {
49 $machine->succeed("expr 1 + 2");
50 };
51
52 # Test that the swap file got created.
53 subtest "swapfile", sub {
54 $machine->waitForUnit("root-swapfile.swap");
55 $machine->succeed("ls -l /root/swapfile | grep 134217728");
56 };
57
58 # Test whether kernel.poweroff_cmd is set.
59 subtest "poweroff_cmd", sub {
60 $machine->succeed("[ -x \"\$(cat /proc/sys/kernel/poweroff_cmd)\" ]")
61 };
62
63 # Test whether the blkio controller is properly enabled.
64 subtest "blkio-cgroup", sub {
65 $machine->succeed("[ -n \"\$(cat /sys/fs/cgroup/blkio/blkio.sectors)\" ]")
66 };
67
68 # Test whether we have a reboot record in wtmp.
69 subtest "reboot-wtmp", sub {
70 $machine->succeed("last | grep reboot >&2");
71 };
72
73 # Test whether we can override environment variables.
74 subtest "override-env-var", sub {
75 $machine->succeed('[ "$EDITOR" = emacs ]');
76 };
77
78 # Test whether hostname (and by extension nss_myhostname) works.
79 subtest "hostname", sub {
80 $machine->succeed('[ "`hostname`" = machine ]');
81 #$machine->succeed('[ "`hostname -s`" = machine ]');
82 };
83
84 # Test whether systemd-udevd automatically loads modules for our hardware.
85 $machine->succeed("systemctl start systemd-udev-settle.service");
86 subtest "udev-auto-load", sub {
87 $machine->waitForUnit('systemd-udev-settle.service');
88 $machine->succeed('lsmod | grep psmouse');
89 };
90
91 # Test whether systemd-tmpfiles-clean works.
92 subtest "tmpfiles", sub {
93 $machine->succeed('touch /tmp/foo');
94 $machine->succeed('systemctl start systemd-tmpfiles-clean');
95 $machine->succeed('[ -e /tmp/foo ]');
96 $machine->succeed('date -s "@$(($(date +%s) + 1000000))"'); # move into the future
97 $machine->succeed('systemctl start systemd-tmpfiles-clean');
98 $machine->fail('[ -e /tmp/foo ]');
99 };
100
101 # Test whether automounting works.
102 subtest "automount", sub {
103 $machine->fail("grep '/tmp2 tmpfs' /proc/mounts");
104 $machine->succeed("touch /tmp2/x");
105 $machine->succeed("grep '/tmp2 tmpfs' /proc/mounts");
106 };
107
108 subtest "shell-vars", sub {
109 $machine->succeed('[ -n "$NIX_PATH" ]');
110 };
111
112 subtest "nix-db", sub {
113 $machine->succeed("nix-store -qR /run/current-system | grep nixos-");
114 };
115
116 # Test sudo
117 subtest "sudo", sub {
118 $machine->succeed("su - sybil -c 'sudo true'");
119 };
120 '';
121})