nixos/testing: Add node.pkgs option

By factoring out this logic, it's easier for other projects to make
use of it this optimization too (and do it correctly).

Changed files
+22 -6
nixos
lib
testing
tests
+21 -1
nixos/lib/testing/nodes.nix
···
testModuleArgs@{ config, lib, hostPkgs, nodes, ... }:
let
-
inherit (lib) mkOption mkForce optional types mapAttrs mkDefault mdDoc;
+
inherit (lib) mkOption mkForce optional types mapAttrs mkDefault mkIf mdDoc;
baseOS =
import ../eval-config.nix {
···
default = { };
};
+
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.
+
'';
+
};
+
node.specialArgs = mkOption {
type = types.lazyAttrsOf types.raw;
default = { };
···
config.nodes;
passthru.nodes = config.nodesCompat;
+
+
defaults = mkIf (config.node.pkgs != null) {
+
nixpkgs.pkgs = config.node.pkgs;
+
imports = [ ../../modules/misc/nixpkgs/read-only.nix ];
+
disabledModules = [{ key = "nodes.nix-pkgs"; }];
+
};
+
};
}
+1 -5
nixos/tests/all-tests.nix
···
# warnIf pkgs.config.allowAliases "nixosTests: pkgs includes aliases."
{
_class = "nixosTest";
-
defaults = {
-
nixpkgs.pkgs = pkgs;
-
imports = [ ../modules/misc/nixpkgs/read-only.nix ];
-
disabledModules = [{ key = "nodes.nix-pkgs"; }];
-
};
+
node.pkgs = pkgs;
};
in {