Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/types: make pattern of strMatching accessible #350467

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/tests/modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions lib/tests/modules/strMatching-merge.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ lib, ... }:
{
imports = [
{
options.sm = lib.mkOption {
type = lib.types.strMatching "\(.*\)";
};
}
{
options.sm = lib.mkOption {
type = lib.types.strMatching "\(.*\)";
};
}
];
}
5 changes: 5 additions & 0 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading