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