1{ config, hostPkgs, lib, ... }:
2let
3 inherit (lib) types mkOption;
4in
5{
6 options = {
7 passthru = mkOption {
8 type = types.lazyAttrsOf types.raw;
9 description = ''
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 rawTestDerivation = mkOption {
20 type = types.package;
21 description = ''
22 Unfiltered version of `test`, for troubleshooting the test framework and `testBuildFailure` in the test framework's test suite.
23 This is not intended for general use. Use `test` instead.
24 '';
25 internal = true;
26 };
27
28 test = mkOption {
29 type = types.package;
30 # TODO: can the interactive driver be configured to access the network?
31 description = ''
32 Derivation that runs the test as its "build" process.
33
34 This implies that NixOS tests run isolated from the network, making them
35 more dependable.
36 '';
37 };
38 };
39
40 config = {
41 rawTestDerivation = hostPkgs.stdenv.mkDerivation {
42 name = "vm-test-run-${config.name}";
43
44 requiredSystemFeatures = [ "nixos-test" ]
45 ++ lib.optionals hostPkgs.stdenv.hostPlatform.isLinux [ "kvm" ]
46 ++ lib.optionals hostPkgs.stdenv.hostPlatform.isDarwin [ "apple-virt" ];
47
48 buildCommand = ''
49 mkdir -p $out
50
51 # effectively mute the XMLLogger
52 export LOGFILE=/dev/null
53
54 ${config.driver}/bin/nixos-test-driver -o $out
55 '';
56
57 passthru = config.passthru;
58
59 meta = config.meta;
60 };
61 test = lib.lazyDerivation { # lazyDerivation improves performance when only passthru items and/or meta are used.
62 derivation = config.rawTestDerivation;
63 inherit (config) passthru meta;
64 };
65
66 # useful for inspection (debugging / exploration)
67 passthru.config = config;
68 };
69}