From eaac7e15048d5a6e19d3800a72e5bd5719a86c31 Mon Sep 17 00:00:00 2001 From: Peter Bynum Date: Mon, 24 Aug 2026 12:00:08 -0400 Subject: [PATCH] nixos/test-driver: coerced testScript merging --- nixos/lib/testing/testScript.nix | 45 +++++++++++++------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/nixos/lib/testing/testScript.nix b/nixos/lib/testing/testScript.nix index 2ba9b682d3cb..591330a40fd8 100644 --- a/nixos/lib/testing/testScript.nix +++ b/nixos/lib/testing/testScript.nix @@ -7,20 +7,15 @@ testModuleArgs@{ ... }: let - inherit (lib) mkOption types; - inherit (types) either lines functionTo; + inherit (lib) mkOption types const; + inherit (types) coercedTo lines functionTo; in { options = { testScript = mkOption { - type = either lines (functionTo lines); - apply = - v: - if lib.isFunction v then - # Only pass args the testScript function expects. - args: v (builtins.intersectAttrs (lib.functionArgs v) args) - else - v; + type = coercedTo lines const (functionTo lines); + # Only pass args the testScript function expects. + apply = v: args: v (builtins.intersectAttrs (lib.functionArgs v) args); description = '' A series of python declarations and statements that you write to perform the test. @@ -50,23 +45,19 @@ in withoutTestScriptReferences.includeTestScriptReferences = false; withoutTestScriptReferences.testScript = lib.mkForce "testscript omitted"; - testScriptString = - if lib.isFunction config.testScript then - config.testScript { - nodes = lib.mapAttrs ( - k: v: - if v.virtualisation.useNixStoreImage then - # prevent infinite recursion when testScript would - # reference v's toplevel - config.withoutTestScriptReferences.nodesCompat.${k} - else - # reuse memoized config - v - ) config.nodesCompat; - containers = config.containers; - } - else - config.testScript; + testScriptString = config.testScript { + nodes = lib.mapAttrs ( + k: v: + if v.virtualisation.useNixStoreImage then + # prevent infinite recursion when testScript would + # reference v's toplevel + config.withoutTestScriptReferences.nodesCompat.${k} + else + # reuse memoized config + v + ) config.nodesCompat; + containers = config.containers; + }; nodeDefaults = { config, name, ... }: