Skip to content

Commit 8282ea0

Browse files
committed
refactor: coerce leaf test modules into derivations
which is much simpler than collecting all the modules and converting them later on. The result is also easier to work with since it's either null or a derivation, as opposed to it potentially being a path or a module.
1 parent ea37f78 commit 8282ea0

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

maintainers/types/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
lib,
3+
pkgs,
4+
sources,
35
...
46
}@args:
57
let

maintainers/types/test.nix

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
*/
4040
{
4141
lib,
42+
pkgs,
43+
sources,
44+
config,
4245
ngiTypes,
4346
...
4447
}:
@@ -52,6 +55,64 @@ let
5255
inherit (ngiTypes)
5356
problem
5457
;
58+
59+
# TODO: move into `lib.nix`?
60+
nixosTest =
61+
test:
62+
let
63+
# Amenities for interactive tests
64+
tools = {
65+
environment.systemPackages = with pkgs; [
66+
vim
67+
tmux
68+
jq
69+
];
70+
# Use kmscon <https://www.freedesktop.org/wiki/Software/kmscon/>
71+
# to provide a slightly nicer console.
72+
# kmscon allows zooming with [Ctrl] + [+] and [Ctrl] + [-]
73+
services.kmscon = {
74+
enable = true;
75+
autologinUser = "root";
76+
fonts = [
77+
{
78+
name = "Hack";
79+
package = pkgs.hack-font;
80+
}
81+
];
82+
};
83+
};
84+
85+
debugging.interactive.nodes = lib.mapAttrs (_: _: tools) test.nodes;
86+
87+
args = {
88+
imports = [
89+
debugging
90+
test
91+
];
92+
# we need to extend pkgs with ngipkgs, so it can't be read-only
93+
node.pkgsReadOnly = false;
94+
};
95+
in
96+
if lib.isDerivation test then
97+
lib.lazyDerivation { derivation = test; }
98+
else if test == null then
99+
null
100+
else
101+
pkgs.testers.runNixOSTest args;
102+
103+
callTest =
104+
module:
105+
if lib.isString module || lib.isPath module then
106+
nixosTest (
107+
import module {
108+
inherit pkgs lib sources;
109+
inherit (pkgs) system;
110+
}
111+
)
112+
else if module == null || config.problem != null then
113+
null
114+
else
115+
nixosTest module;
55116
in
56117

57118
{
@@ -65,7 +126,7 @@ in
65126
# This is because test nodes are eagerly evaluated to create the
66127
# driver's `vmStartScripts` (see `nixos/lib/testing/driver.nix` in
67128
# NixOS).
68-
type = with types; nullOr (either deferredModule package);
129+
type = with types; nullOr (coercedTo (either deferredModule package) callTest package);
69130
default = null;
70131
description = "NixOS test module";
71132
};

0 commit comments

Comments
 (0)