1{ lib, pkgs, ... }:
2
3{
4 name = "nixos-init";
5
6 meta.maintainers = with lib.maintainers; [ nikstur ];
7
8 nodes.machine =
9 { modulesPath, ... }:
10 {
11 imports = [
12 "${modulesPath}/profiles/perlless.nix"
13 ];
14 virtualisation.mountHostNixStore = false;
15 virtualisation.useNixStoreImage = true;
16
17 system.nixos-init.enable = true;
18 # Forcibly set this to only these specific values.
19 boot.nixStoreMountOpts = lib.mkForce [
20 "nodev"
21 "nosuid"
22 ];
23 };
24
25 testScript =
26 { nodes, ... }: # python
27 ''
28 with subtest("init"):
29 with subtest("/nix/store is mounted with the correct options"):
30 findmnt_output = machine.succeed("findmnt --direction backward --first-only --noheadings --output OPTIONS /nix/store").strip()
31 print(findmnt_output)
32 t.assertIn("nodev", findmnt_output)
33 t.assertIn("nosuid", findmnt_output)
34
35 t.assertEqual("${nodes.machine.system.build.toplevel}", machine.succeed("readlink /run/booted-system").strip())
36
37 with subtest("activation"):
38 t.assertEqual("${nodes.machine.system.build.toplevel}", machine.succeed("readlink /run/current-system").strip())
39 t.assertEqual("${nodes.machine.hardware.firmware}/lib/firmware", machine.succeed("cat /sys/module/firmware_class/parameters/path").strip())
40 t.assertEqual("${pkgs.kmod}/bin/modprobe", machine.succeed("cat /proc/sys/kernel/modprobe").strip())
41 t.assertEqual("${nodes.machine.environment.usrbinenv}", machine.succeed("readlink /usr/bin/env").strip())
42 t.assertEqual("${nodes.machine.environment.binsh}", machine.succeed("readlink /bin/sh").strip())
43
44 machine.wait_for_unit("multi-user.target")
45 with subtest("systemd state passing"):
46 systemd_analyze_output = machine.succeed("systemd-analyze")
47 print(systemd_analyze_output)
48 t.assertIn("(initrd)", systemd_analyze_output, "systemd-analyze has no information about the initrd")
49
50 ps_output = machine.succeed("ps ax -o command | grep systemd | head -n 1")
51 print(ps_output)
52 t.assertIn("--deserialize", ps_output, "--deserialize flag wasn't passed to systemd")
53 '';
54}