From f659db7ba28e8474df72cb505c790ff2cf92c1a4 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 7 May 2023 17:10:40 +0200 Subject: [PATCH] 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). --- nixos/lib/testing/nodes.nix | 22 +++++++++++++++++++++- nixos/tests/all-tests.nix | 6 +----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/nixos/lib/testing/nodes.nix b/nixos/lib/testing/nodes.nix index 5a6b30b8f8d5..d1238a374f24 100644 --- a/nixos/lib/testing/nodes.nix +++ b/nixos/lib/testing/nodes.nix @@ -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"; }]; + }; + }; } diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 9abe419b1c03..ccdd572e5ece 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -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 {