summary refs log tree commit diff
path: root/nixos/lib/testing
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2023-05-07 17:39:08 +0200
committerRobert Hensing <robert@roberthensing.nl>2023-05-11 16:24:01 +0200
commit0f83261f0e2ccfa116076d1848550d1b6bccc852 (patch)
treee8a0eb009e6b3664147aa19e01d911fc776ea626 /nixos/lib/testing
parentf659db7ba28e8474df72cb505c790ff2cf92c1a4 (diff)
downloadnixpkgs-0f83261f0e2ccfa116076d1848550d1b6bccc852.tar
nixpkgs-0f83261f0e2ccfa116076d1848550d1b6bccc852.tar.gz
nixpkgs-0f83261f0e2ccfa116076d1848550d1b6bccc852.tar.bz2
nixpkgs-0f83261f0e2ccfa116076d1848550d1b6bccc852.tar.lz
nixpkgs-0f83261f0e2ccfa116076d1848550d1b6bccc852.tar.xz
nixpkgs-0f83261f0e2ccfa116076d1848550d1b6bccc852.tar.zst
nixpkgs-0f83261f0e2ccfa116076d1848550d1b6bccc852.zip
nixos/testing: Add node.pkgsReadOnly escape hatch
By adding this option indirection, a test can declare all by itself
that it needs a custom nixpkgs. This is a more convenient way of
going about this when the caller of the test framework receives a
`node.pkgs` unconditionally.
Diffstat (limited to 'nixos/lib/testing')
-rw-r--r--nixos/lib/testing/nodes.nix25
1 files changed, 23 insertions, 2 deletions
diff --git a/nixos/lib/testing/nodes.nix b/nixos/lib/testing/nodes.nix
index d1238a374f2..0197097e888 100644
--- a/nixos/lib/testing/nodes.nix
+++ b/nixos/lib/testing/nodes.nix
@@ -1,7 +1,17 @@
 testModuleArgs@{ config, lib, hostPkgs, nodes, ... }:
 
 let
-  inherit (lib) mkOption mkForce optional types mapAttrs mkDefault mkIf mdDoc;
+  inherit (lib)
+    literalExpression
+    literalMD
+    mapAttrs
+    mdDoc
+    mkDefault
+    mkIf
+    mkOption mkForce
+    optional
+    types
+    ;
 
   baseOS =
     import ../eval-config.nix {
@@ -85,6 +95,17 @@ in
       '';
     };
 
+    node.pkgsReadOnly = mkOption {
+      description = mdDoc ''
+        Whether to make the `nixpkgs.*` options read-only. This is only relevant when [`node.pkgs`](#test-opt-node.pkgs) is set.
+
+        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.
+      '';
+      type = types.bool;
+      default = config.node.pkgs != null;
+      defaultText = literalExpression ''node.pkgs != null'';
+    };
+
     node.specialArgs = mkOption {
       type = types.lazyAttrsOf types.raw;
       default = { };
@@ -118,7 +139,7 @@ in
 
     passthru.nodes = config.nodesCompat;
 
-    defaults = mkIf (config.node.pkgs != null) {
+    defaults = mkIf config.node.pkgsReadOnly {
       nixpkgs.pkgs = config.node.pkgs;
       imports = [ ../../modules/misc/nixpkgs/read-only.nix ];
       disabledModules = [{ key = "nodes.nix-pkgs"; }];