lib/types: make pattern of strMatching accessible (#350467)

This commit is contained in:
Silvan Mosberger 2024-12-09 17:53:38 +01:00 committed by GitHub
commit 33fe023937
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 0 deletions

View file

@ -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

View file

@ -0,0 +1,15 @@
{ lib, ... }:
{
imports = [
{
options.sm = lib.mkOption {
type = lib.types.strMatching "\(.*\)";
};
}
{
options.sm = lib.mkOption {
type = lib.types.strMatching "\(.*\)";
};
}
];
}

View file

@ -461,6 +461,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