2022-06-06 11:29:04 +00:00
testModuleArgs @ { config , lib , hostPkgs , nodes , . . . }:
let
2023-05-07 15:39:08 +00:00
inherit ( lib )
literalExpression
literalMD
mapAttrs
mdDoc
mkDefault
mkIf
mkOption mkForce
optional
2023-05-07 15:47:29 +00:00
optionalAttrs
2023-05-07 15:39:08 +00:00
types
;
2022-06-06 11:29:04 +00:00
baseOS =
import ../eval-config.nix {
2023-05-07 13:38:58 +00:00
system = null ; # use modularly defined system
2022-06-06 11:29:04 +00:00
inherit ( config . node ) specialArgs ;
modules = [ config . defaults ] ;
baseModules = ( import ../../modules/module-list.nix ) ++
[
2022-06-21 23:12:01 +00:00
./nixos-test-base.nix
2022-06-27 18:07:08 +00:00
{ key = " n o d e s " ; _module . args . nodes = config . nodesCompat ; }
2022-06-06 11:29:04 +00:00
( { config , . . . }:
{
virtualisation . qemu . package = testModuleArgs . config . qemu . package ;
2023-05-07 13:38:58 +00:00
} )
2023-05-07 15:47:29 +00:00
( optionalAttrs ( ! config . node . pkgsReadOnly ) {
2023-05-07 13:44:54 +00:00
key = " n o d e s . n i x - p k g s " ;
2023-05-07 13:38:58 +00:00
config = {
2022-06-06 11:29:04 +00:00
# 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 ;
2023-05-07 13:38:58 +00:00
# TODO: switch to nixpkgs.hostPlatform and make sure containers-imperative test still evaluates.
nixpkgs . system = hostPkgs . stdenv . hostPlatform . system ;
} ;
} )
2022-09-17 13:34:14 +00:00
testModuleArgs . config . extraBaseModules
2022-12-20 13:28:47 +00:00
] ;
2022-06-06 11:29:04 +00:00
} ;
in
{
options = {
node . type = mkOption {
type = types . raw ;
default = baseOS . type ;
internal = true ;
} ;
nodes = mkOption {
type = types . lazyAttrsOf config . node . type ;
2022-06-27 18:06:30 +00:00
visible = " s h a l l o w " ;
description = mdDoc ''
An attribute set of NixOS configuration modules .
2022-09-29 10:41:59 +00:00
The configurations are augmented by the [ ` defaults ` ] ( #test-opt-defaults) option.
2022-06-27 18:06:30 +00: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 11:29:04 +00:00
} ;
defaults = mkOption {
2022-06-27 18:06:30 +00:00
description = mdDoc ''
2022-09-29 10:41:59 +00:00
NixOS configuration that is applied to all [ { option } ` nodes ` ] ( #test-opt-nodes).
2022-06-27 18:06:30 +00:00
'' ;
type = types . deferredModule ;
default = { } ;
} ;
extraBaseModules = mkOption {
description = mdDoc ''
2022-09-29 10:41:59 +00: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 11:29:04 +00:00
'' ;
type = types . deferredModule ;
default = { } ;
} ;
2023-05-07 15:10:40 +00:00
node . pkgs = mkOption {
description = mdDoc ''
The Nixpkgs to use for the nodes .
Setting this will make the ` nixpkgs . * ` options read-only , to avoid mistakenly testing with a Nixpkgs configuration that diverges from regular use .
'' ;
type = types . nullOr types . pkgs ;
default = null ;
defaultText = literalMD ''
` null ` , so construct ` pkgs ` according to the ` nixpkgs . * ` options as usual .
'' ;
} ;
2023-05-07 15:39:08 +00:00
node . pkgsReadOnly = mkOption {
description = mdDoc ''
Whether to make the ` nixpkgs . * ` options read-only . This is only relevant when [ ` node . pkgs ` ] ( #test-opt-node.pkgs) is set.
Set this to ` false ` when any of the [ ` nodes ` ] ( #test-opt-nodes) needs to configure any of the `nixpkgs.*` options. This will slow down evaluation of your test a bit.
'' ;
type = types . bool ;
default = config . node . pkgs != null ;
defaultText = literalExpression '' n o d e . p k g s ! = n u l l '' ;
} ;
2022-06-06 11:29:04 +00:00
node . specialArgs = mkOption {
type = types . lazyAttrsOf types . raw ;
default = { } ;
2022-06-27 18:06:30 +00: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 11:29:04 +00:00
} ;
nodesCompat = mkOption {
internal = true ;
2022-06-27 18:06:30 +00:00
description = mdDoc ''
Basically ` _module . args . nodes ` , but with backcompat and warnings added .
This will go away .
'' ;
2022-06-06 11:29:04 +00:00
} ;
} ;
config = {
_module . args . nodes = config . nodesCompat ;
nodesCompat =
mapAttrs
( name : config : config // {
2022-10-16 14:19:29 +00:00
config = lib . warnIf ( lib . isInOldestRelease 2211 )
2022-06-06 11:29:04 +00: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 ;
2023-05-07 15:10:40 +00:00
2023-05-07 15:39:08 +00:00
defaults = mkIf config . node . pkgsReadOnly {
2023-05-07 15:10:40 +00:00
nixpkgs . pkgs = config . node . pkgs ;
imports = [ ../../modules/misc/nixpkgs/read-only.nix ] ;
} ;
2022-06-06 11:29:04 +00:00
} ;
}