From ad7b2f343896360eb8ac9fd8815304758356750a Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 22 Oct 2024 13:34:20 +0200 Subject: [PATCH 1/2] lib/types: make pattern of strMatching accessible --- lib/types.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/types.nix b/lib/types.nix index 6c4a66c4e3c0..5da3580c17b0 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -443,6 +443,11 @@ rec { descriptionClass = "noun"; check = x: str.check x && builtins.match pattern x != null; inherit (str) merge; + functor = defaultFunctor "strMatching" // { + type = payload: strMatching payload.pattern; + payload = { inherit pattern; }; + binOp = lhs: rhs: if lhs == rhs then lhs else null; + }; }; # Merge multiple definitions by concatenating them (with the given From 3fe041e8bfddfd618661f050fb23a579ba6ac373 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 2/2] lib.types: Add test for merging strMatching --- lib/tests/modules.sh | 3 +++ lib/tests/modules/strMatching-merge.nix | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 lib/tests/modules/strMatching-merge.nix diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index ad2ea44c361a..c38398576092 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -190,6 +190,9 @@ checkConfigOutput '^420$' config.bare-submodule.deep ./declare-bare-submodule.ni checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./define-shorthandOnlyDefinesConfig-true.nix checkConfigError 'The option .bare-submodule.deep. in .*/declare-bare-submodule-deep-option.nix. is already declared in .*/declare-bare-submodule-deep-option-duplicate.nix' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./declare-bare-submodule-deep-option-duplicate.nix +# Check that strMatching can be merged +checkConfigOutput '^"strMatching.*"$' options.sm.type.name ./strMatching-merge.nix + # Check integer types. # unsigned checkConfigOutput '^42$' config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix diff --git a/lib/tests/modules/strMatching-merge.nix b/lib/tests/modules/strMatching-merge.nix new file mode 100644 index 000000000000..2e043a5f9723 --- /dev/null +++ b/lib/tests/modules/strMatching-merge.nix @@ -0,0 +1,15 @@ +{ lib, ... }: +{ + imports = [ + { + options.sm = lib.mkOption { + type = lib.types.strMatching "\(.*\)"; + }; + } + { + options.sm = lib.mkOption { + type = lib.types.strMatching "\(.*\)"; + }; + } + ]; +}