at 23.05-pre 3.6 kB view raw
1testModuleArgs@{ config, lib, hostPkgs, nodes, ... }: 2 3let 4 inherit (lib) mkOption mkForce optional types mapAttrs mkDefault mdDoc; 5 6 system = hostPkgs.stdenv.hostPlatform.system; 7 8 baseOS = 9 import ../eval-config.nix { 10 inherit system; 11 inherit (config.node) specialArgs; 12 modules = [ config.defaults ]; 13 baseModules = (import ../../modules/module-list.nix) ++ 14 [ 15 ./nixos-test-base.nix 16 { key = "nodes"; _module.args.nodes = config.nodesCompat; } 17 ({ config, ... }: 18 { 19 virtualisation.qemu.package = testModuleArgs.config.qemu.package; 20 21 # Ensure we do not use aliases. Ideally this is only set 22 # when the test framework is used by Nixpkgs NixOS tests. 23 nixpkgs.config.allowAliases = false; 24 }) 25 testModuleArgs.config.extraBaseModules 26 ] ++ optional config.minimal ../../modules/testing/minimal-kernel.nix; 27 }; 28 29 30in 31 32{ 33 34 options = { 35 node.type = mkOption { 36 type = types.raw; 37 default = baseOS.type; 38 internal = true; 39 }; 40 41 nodes = mkOption { 42 type = types.lazyAttrsOf config.node.type; 43 visible = "shallow"; 44 description = mdDoc '' 45 An attribute set of NixOS configuration modules. 46 47 The configurations are augmented by the [`defaults`](#test-opt-defaults) option. 48 49 They are assigned network addresses according to the `nixos/lib/testing/network.nix` module. 50 51 A few special options are available, that aren't in a plain NixOS configuration. See [Configuring the nodes](#sec-nixos-test-nodes) 52 ''; 53 }; 54 55 defaults = mkOption { 56 description = mdDoc '' 57 NixOS configuration that is applied to all [{option}`nodes`](#test-opt-nodes). 58 ''; 59 type = types.deferredModule; 60 default = { }; 61 }; 62 63 extraBaseModules = mkOption { 64 description = mdDoc '' 65 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). 66 ''; 67 type = types.deferredModule; 68 default = { }; 69 }; 70 71 node.specialArgs = mkOption { 72 type = types.lazyAttrsOf types.raw; 73 default = { }; 74 description = mdDoc '' 75 An attribute set of arbitrary values that will be made available as module arguments during the resolution of module `imports`. 76 77 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. 78 ''; 79 }; 80 81 minimal = mkOption { 82 type = types.bool; 83 default = false; 84 description = mdDoc '' 85 Enable to configure all [{option}`nodes`](#test-opt-nodes) to run with a minimal kernel. 86 ''; 87 }; 88 89 nodesCompat = mkOption { 90 internal = true; 91 description = mdDoc '' 92 Basically `_module.args.nodes`, but with backcompat and warnings added. 93 94 This will go away. 95 ''; 96 }; 97 }; 98 99 config = { 100 _module.args.nodes = config.nodesCompat; 101 nodesCompat = 102 mapAttrs 103 (name: config: config // { 104 config = lib.warnIf (lib.isInOldestRelease 2211) 105 "Module argument `nodes.${name}.config` is deprecated. Use `nodes.${name}` instead." 106 config; 107 }) 108 config.nodes; 109 110 passthru.nodes = config.nodesCompat; 111 }; 112}