2022-09-30 11:47:45 +00:00
|
|
|
{ config, hostPkgs, lib, ... }:
|
|
|
|
let
|
2024-04-21 15:54:59 +00:00
|
|
|
inherit (lib) types mkOption;
|
2022-09-30 11:47:45 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
passthru = mkOption {
|
|
|
|
type = types.lazyAttrsOf types.raw;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-09-30 11:47:45 +00:00
|
|
|
Attributes to add to the returned derivations,
|
|
|
|
which are not necessarily part of the build.
|
|
|
|
|
|
|
|
This is a bit like doing `drv // { myAttr = true; }` (which would be lost by `overrideAttrs`).
|
|
|
|
It does not change the actual derivation, but adds the attribute nonetheless, so that
|
|
|
|
consumers of what would be `drv` have more information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
rawTestDerivation = mkOption {
|
|
|
|
type = types.package;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
Unfiltered version of `test`, for troubleshooting the test framework and `testBuildFailure` in the test framework's test suite.
|
|
|
|
This is not intended for general use. Use `test` instead.
|
|
|
|
'';
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
|
2022-09-30 11:47:45 +00:00
|
|
|
test = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
# TODO: can the interactive driver be configured to access the network?
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-09-30 11:47:45 +00:00
|
|
|
Derivation that runs the test as its "build" process.
|
|
|
|
|
|
|
|
This implies that NixOS tests run isolated from the network, making them
|
|
|
|
more dependable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2023-11-16 04:20:00 +00:00
|
|
|
rawTestDerivation = hostPkgs.stdenv.mkDerivation {
|
|
|
|
name = "vm-test-run-${config.name}";
|
2022-09-30 11:47:45 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
requiredSystemFeatures = [ "nixos-test" ]
|
|
|
|
++ lib.optionals hostPkgs.stdenv.hostPlatform.isLinux [ "kvm" ]
|
|
|
|
++ lib.optionals hostPkgs.stdenv.hostPlatform.isDarwin [ "apple-virt" ];
|
2022-09-30 11:47:45 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out
|
2022-09-30 11:47:45 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
# effectively mute the XMLLogger
|
|
|
|
export LOGFILE=/dev/null
|
2022-09-30 11:47:45 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
${config.driver}/bin/nixos-test-driver -o $out
|
|
|
|
'';
|
2022-09-30 11:47:45 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
passthru = config.passthru;
|
2022-09-30 11:47:45 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
meta = config.meta;
|
|
|
|
};
|
|
|
|
test = lib.lazyDerivation { # lazyDerivation improves performance when only passthru items and/or meta are used.
|
|
|
|
derivation = config.rawTestDerivation;
|
2022-09-30 11:47:45 +00:00
|
|
|
inherit (config) passthru meta;
|
|
|
|
};
|
|
|
|
|
|
|
|
# useful for inspection (debugging / exploration)
|
|
|
|
passthru.config = config;
|
|
|
|
};
|
|
|
|
}
|