1{ config, hostPkgs, lib, ... }:
2let
3 inherit (lib) types mkOption mdDoc;
4in
5{
6 options = {
7 passthru = mkOption {
8 type = types.lazyAttrsOf types.raw;
9 description = mdDoc ''
10 Attributes to add to the returned derivations,
11 which are not necessarily part of the build.
12
13 This is a bit like doing `drv // { myAttr = true; }` (which would be lost by `overrideAttrs`).
14 It does not change the actual derivation, but adds the attribute nonetheless, so that
15 consumers of what would be `drv` have more information.
16 '';
17 };
18
19 test = mkOption {
20 type = types.package;
21 # TODO: can the interactive driver be configured to access the network?
22 description = mdDoc ''
23 Derivation that runs the test as its "build" process.
24
25 This implies that NixOS tests run isolated from the network, making them
26 more dependable.
27 '';
28 };
29 };
30
31 config = {
32 test = lib.lazyDerivation { # lazyDerivation improves performance when only passthru items and/or meta are used.
33 derivation = hostPkgs.stdenv.mkDerivation {
34 name = "vm-test-run-${config.name}";
35
36 requiredSystemFeatures = [ "kvm" "nixos-test" ];
37
38 buildCommand = ''
39 mkdir -p $out
40
41 # effectively mute the XMLLogger
42 export LOGFILE=/dev/null
43
44 ${config.driver}/bin/nixos-test-driver -o $out
45 '';
46
47 passthru = config.passthru;
48
49 meta = config.meta;
50 };
51 inherit (config) passthru meta;
52 };
53
54 # useful for inspection (debugging / exploration)
55 passthru.config = config;
56 };
57}