about summary refs log tree commit diff
path: root/nixos/lib
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2023-05-07 17:10:40 +0200
committerRobert Hensing <robert@roberthensing.nl>2023-05-11 16:24:00 +0200
commitf659db7ba28e8474df72cb505c790ff2cf92c1a4 (patch)
tree1a0074a9d0be3d9dbc54f427b0327d8a8a82d644 /nixos/lib
parentd0b0f9e441c70253ea4ba42162b5e60057ba6883 (diff)
downloadnixlib-f659db7ba28e8474df72cb505c790ff2cf92c1a4.tar
nixlib-f659db7ba28e8474df72cb505c790ff2cf92c1a4.tar.gz
nixlib-f659db7ba28e8474df72cb505c790ff2cf92c1a4.tar.bz2
nixlib-f659db7ba28e8474df72cb505c790ff2cf92c1a4.tar.lz
nixlib-f659db7ba28e8474df72cb505c790ff2cf92c1a4.tar.xz
nixlib-f659db7ba28e8474df72cb505c790ff2cf92c1a4.tar.zst
nixlib-f659db7ba28e8474df72cb505c790ff2cf92c1a4.zip
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).
Diffstat (limited to 'nixos/lib')
-rw-r--r--nixos/lib/testing/nodes.nix22
1 files changed, 21 insertions, 1 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"; }];
+    };
+
   };
 }