1 testModuleArgs@{ config, lib, hostPkgs, nodes, ... }:
16 inherit (hostPkgs.stdenv) hostPlatform;
19 if hostPlatform.isLinux
20 then hostPlatform.system
24 "x86_64-darwin" = "x86_64-linux";
25 "aarch64-darwin" = "aarch64-linux";
28 supportedHosts = lib.concatStringsSep ", " (lib.attrNames hostToGuest);
31 "NixOS Test: don't know which VM guest system to pair with VM host system: ${hostPlatform.system}. Perhaps you intended to run the tests on a Linux host, or one of the following systems that may run NixOS tests: ${supportedHosts}";
33 hostToGuest.${hostPlatform.system} or (throw message);
36 import ../eval-config.nix {
38 system = null; # use modularly defined system
39 inherit (config.node) specialArgs;
40 modules = [ config.defaults ];
41 baseModules = (import ../../modules/module-list.nix) ++
44 { key = "nodes"; _module.args.nodes = config.nodesCompat; }
47 virtualisation.qemu.package = testModuleArgs.config.qemu.package;
48 virtualisation.host.pkgs = hostPkgs;
51 key = "nodes.nix-pkgs";
52 config = optionalAttrs (!config.node.pkgsReadOnly) (
53 mkIf (!options.nixpkgs.pkgs.isDefined) {
54 # TODO: switch to nixpkgs.hostPlatform and make sure containers-imperative test still evaluates.
55 nixpkgs.system = guestSystem;
59 testModuleArgs.config.extraBaseModules
69 node.type = mkOption {
71 default = baseOS.type;
76 type = types.lazyAttrsOf config.node.type;
79 An attribute set of NixOS configuration modules.
81 The configurations are augmented by the [`defaults`](#test-opt-defaults) option.
83 They are assigned network addresses according to the `nixos/lib/testing/network.nix` module.
85 A few special options are available, that aren't in a plain NixOS configuration. See [Configuring the nodes](#sec-nixos-test-nodes)
91 NixOS configuration that is applied to all [{option}`nodes`](#test-opt-nodes).
93 type = types.deferredModule;
97 extraBaseModules = mkOption {
99 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).
101 type = types.deferredModule;
105 node.pkgs = mkOption {
107 The Nixpkgs to use for the nodes.
109 Setting this will make the `nixpkgs.*` options read-only, to avoid mistakenly testing with a Nixpkgs configuration that diverges from regular use.
111 type = types.nullOr types.pkgs;
113 defaultText = literalMD ''
114 `null`, so construct `pkgs` according to the `nixpkgs.*` options as usual.
118 node.pkgsReadOnly = mkOption {
120 Whether to make the `nixpkgs.*` options read-only. This is only relevant when [`node.pkgs`](#test-opt-node.pkgs) is set.
122 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.
125 default = config.node.pkgs != null;
126 defaultText = literalExpression ''node.pkgs != null'';
129 node.specialArgs = mkOption {
130 type = types.lazyAttrsOf types.raw;
133 An attribute set of arbitrary values that will be made available as module arguments during the resolution of module `imports`.
135 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.
139 nodesCompat = mkOption {
142 Basically `_module.args.nodes`, but with backcompat and warnings added.
150 _module.args.nodes = config.nodesCompat;
153 (name: config: config // {
154 config = lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2211)
155 "Module argument `nodes.${name}.config` is deprecated. Use `nodes.${name}` instead."
160 passthru.nodes = config.nodesCompat;
162 defaults = mkIf config.node.pkgsReadOnly {
163 nixpkgs.pkgs = config.node.pkgs;
164 imports = [ ../../modules/misc/nixpkgs/read-only.nix ];