2022-06-06 13:29:04 +02:00
testModuleArgs @ { config , lib , hostPkgs , nodes , . . . }:
let
2022-06-27 20:06:30 +02:00
inherit ( lib ) mkOption mkForce optional types mapAttrs mkDefault mdDoc ;
2022-06-06 13:29:04 +02:00
system = hostPkgs . stdenv . hostPlatform . system ;
baseOS =
import ../eval-config.nix {
inherit system ;
inherit ( config . node ) specialArgs ;
modules = [ config . defaults ] ;
baseModules = ( import ../../modules/module-list.nix ) ++
[
2022-06-22 01:12:01 +02:00
./nixos-test-base.nix
2022-06-27 20:07:08 +02:00
{ key = " n o d e s " ; _module . args . nodes = config . nodesCompat ; }
2022-06-06 13:29:04 +02:00
( { config , . . . }:
{
virtualisation . qemu . package = testModuleArgs . config . qemu . package ;
# Ensure we do not use aliases. Ideally this is only set
# when the test framework is used by Nixpkgs NixOS tests.
nixpkgs . config . allowAliases = false ;
} )
2022-09-17 15:34:14 +02:00
testModuleArgs . config . extraBaseModules
2022-06-06 13:29:04 +02:00
] ++ optional config . minimal ../../modules/testing/minimal-kernel.nix ;
} ;
in
{
options = {
node . type = mkOption {
type = types . raw ;
default = baseOS . type ;
internal = true ;
} ;
nodes = mkOption {
type = types . lazyAttrsOf config . node . type ;
2022-06-27 20:06:30 +02:00
visible = " s h a l l o w " ;
description = mdDoc ''
An attribute set of NixOS configuration modules .
2022-09-29 12:41:59 +02:00
The configurations are augmented by the [ ` defaults ` ] ( #test-opt-defaults) option.
2022-06-27 20:06:30 +02:00
They are assigned network addresses according to the ` nixos/lib/testing/network.nix ` module .
A few special options are available , that aren't in a plain NixOS configuration . See [ Configuring the nodes ] ( #sec-nixos-test-nodes)
'' ;
2022-06-06 13:29:04 +02:00
} ;
defaults = mkOption {
2022-06-27 20:06:30 +02:00
description = mdDoc ''
2022-09-29 12:41:59 +02:00
NixOS configuration that is applied to all [ { option } ` nodes ` ] ( #test-opt-nodes).
2022-06-27 20:06:30 +02:00
'' ;
type = types . deferredModule ;
default = { } ;
} ;
extraBaseModules = mkOption {
description = mdDoc ''
2022-09-29 12:41:59 +02:00
NixOS configuration that , like [ { option } ` defaults ` ] ( #test-opt-defaults), is applied to all [{option}`nodes`](#test-opt-nodes) and can not be undone with [`specialisation.<name>.inheritParentConfig`](https://search.nixos.org/options?show=specialisation.%3Cname%3E.inheritParentConfig&from=0&size=50&sort=relevance&type=packages&query=specialisation).
2022-06-06 13:29:04 +02:00
'' ;
type = types . deferredModule ;
default = { } ;
} ;
node . specialArgs = mkOption {
type = types . lazyAttrsOf types . raw ;
default = { } ;
2022-06-27 20:06:30 +02:00
description = mdDoc ''
An attribute set of arbitrary values that will be made available as module arguments during the resolution of module ` imports ` .
Note that it is not possible to override these from within the NixOS configurations . If you argument is not relevant to ` imports ` , consider setting { option } ` defaults . _module . args . <name> ` instead .
'' ;
2022-06-06 13:29:04 +02:00
} ;
minimal = mkOption {
type = types . bool ;
default = false ;
2022-06-27 20:06:30 +02:00
description = mdDoc ''
2022-09-29 12:41:59 +02:00
Enable to configure all [ { option } ` nodes ` ] ( #test-opt-nodes) to run with a minimal kernel.
2022-06-27 20:06:30 +02:00
'' ;
2022-06-06 13:29:04 +02:00
} ;
nodesCompat = mkOption {
internal = true ;
2022-06-27 20:06:30 +02:00
description = mdDoc ''
Basically ` _module . args . nodes ` , but with backcompat and warnings added .
This will go away .
'' ;
2022-06-06 13:29:04 +02:00
} ;
} ;
config = {
_module . args . nodes = config . nodesCompat ;
nodesCompat =
mapAttrs
( name : config : config // {
2022-10-16 16:19:29 +02:00
config = lib . warnIf ( lib . isInOldestRelease 2211 )
2022-06-06 13:29:04 +02:00
" M o d u l e a r g u m e n t ` n o d e s . ${ name } . c o n f i g ` i s d e p r e c a t e d . U s e ` n o d e s . ${ name } ` i n s t e a d . "
config ;
} )
config . nodes ;
passthru . nodes = config . nodesCompat ;
} ;
}