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).
This commit is contained in:
Robert Hensing 2023-05-07 17:10:40 +02:00
parent d0b0f9e441
commit f659db7ba2
2 changed files with 22 additions and 6 deletions

View file

@ -1,7 +1,7 @@
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 {
@ -72,6 +72,19 @@ in
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 = { };
@ -104,5 +117,12 @@ in
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"; }];
};
};
}

View file

@ -79,11 +79,7 @@ let
# 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 {