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 security.hideProcessInformation = true;
29 users.users.alice = { isNormalUser = true; extraGroups = [ "proc" ]; };
30 };
31
32 testScript =
33 ''
34 subtest "nixos-version", sub {
35 $machine->succeed("[ `nixos-version | wc -w` = 2 ]");
36 };
37
38 subtest "nixos-rebuild", sub {
39 $machine->succeed("nixos-rebuild --help | grep SYNOPSIS");
40 };
41
42 # Sanity check for uid/gid assignment.
43 subtest "users-groups", sub {
44 $machine->succeed("[ `id -u messagebus` = 4 ]");
45 $machine->succeed("[ `id -g messagebus` = 4 ]");
46 $machine->succeed("[ `getent group users` = 'users:x:100:' ]");
47 };
48
49 # Regression test for GMP aborts on QEMU.
50 subtest "gmp", sub {
51 $machine->succeed("expr 1 + 2");
52 };
53
54 # Test that the swap file got created.
55 subtest "swapfile", sub {
56 $machine->waitForUnit("root-swapfile.swap");
57 $machine->succeed("ls -l /root/swapfile | grep 134217728");
58 };
59
60 # Test whether kernel.poweroff_cmd is set.
61 subtest "poweroff_cmd", sub {
62 $machine->succeed("[ -x \"\$(cat /proc/sys/kernel/poweroff_cmd)\" ]")
63 };
64
65 # Test whether the blkio controller is properly enabled.
66 subtest "blkio-cgroup", sub {
67 $machine->succeed("[ -n \"\$(cat /sys/fs/cgroup/blkio/blkio.sectors)\" ]")
68 };
69
70 # Test whether we have a reboot record in wtmp.
71 subtest "reboot-wtmp", sub {
72 $machine->succeed("last | grep reboot >&2");
73 };
74
75 # Test whether we can override environment variables.
76 subtest "override-env-var", sub {
77 $machine->succeed('[ "$EDITOR" = emacs ]');
78 };
79
80 # Test whether hostname (and by extension nss_myhostname) works.
81 subtest "hostname", sub {
82 $machine->succeed('[ "`hostname`" = machine ]');
83 #$machine->succeed('[ "`hostname -s`" = machine ]');
84 };
85
86 # Test whether systemd-udevd automatically loads modules for our hardware.
87 $machine->succeed("systemctl start systemd-udev-settle.service");
88 subtest "udev-auto-load", sub {
89 $machine->waitForUnit('systemd-udev-settle.service');
90 $machine->succeed('lsmod | grep psmouse');
91 };
92
93 # Test whether systemd-tmpfiles-clean works.
94 subtest "tmpfiles", sub {
95 $machine->succeed('touch /tmp/foo');
96 $machine->succeed('systemctl start systemd-tmpfiles-clean');
97 $machine->succeed('[ -e /tmp/foo ]');
98 $machine->succeed('date -s "@$(($(date +%s) + 1000000))"'); # move into the future
99 $machine->succeed('systemctl start systemd-tmpfiles-clean');
100 $machine->fail('[ -e /tmp/foo ]');
101 };
102
103 # Test whether automounting works.
104 subtest "automount", sub {
105 $machine->fail("grep '/tmp2 tmpfs' /proc/mounts");
106 $machine->succeed("touch /tmp2/x");
107 $machine->succeed("grep '/tmp2 tmpfs' /proc/mounts");
108 };
109
110 subtest "shell-vars", sub {
111 $machine->succeed('[ -n "$NIX_PATH" ]');
112 };
113
114 subtest "nix-db", sub {
115 $machine->succeed("nix-store -qR /run/current-system | grep nixos-");
116 };
117
118 # Test sudo
119 subtest "sudo", sub {
120 $machine->succeed("su - sybil -c 'sudo true'");
121 };
122
123 # Test hidepid
124 subtest "hidepid", sub {
125 $machine->succeed("grep -Fq hidepid=2 /etc/mtab");
126 $machine->succeed("[ `su - sybil -c 'pgrep -c -u root'` = 0 ]");
127 $machine->succeed("[ `su - alice -c 'pgrep -c -u root'` != 0 ]");
128 };
129 '';
130})