mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-11 12:15:34 +03:00
lib.types: Add unique like uniq, but custom errors
Couldn't extend types.uniq and it had a silly name anyway. Now we can have better error messages.
This commit is contained in:
parent
ccb85a53b6
commit
ba3e91ed43
3 changed files with 23 additions and 3 deletions
|
@ -32,7 +32,6 @@ let
|
|||
last
|
||||
length
|
||||
tail
|
||||
unique
|
||||
;
|
||||
inherit (lib.attrsets)
|
||||
attrNames
|
||||
|
@ -48,6 +47,7 @@ let
|
|||
mergeDefaultOption
|
||||
mergeEqualOption
|
||||
mergeOneOption
|
||||
mergeUniqueOption
|
||||
showFiles
|
||||
showOption
|
||||
;
|
||||
|
@ -470,6 +470,18 @@ rec {
|
|||
nestedTypes.elemType = elemType;
|
||||
};
|
||||
|
||||
unique = { message }: type: mkOptionType rec {
|
||||
name = "unique";
|
||||
inherit (type) description check;
|
||||
merge = mergeUniqueOption { inherit message; };
|
||||
emptyValue = type.emptyValue;
|
||||
getSubOptions = type.getSubOptions;
|
||||
getSubModules = type.getSubModules;
|
||||
substSubModules = m: uniq (type.substSubModules m);
|
||||
functor = (defaultFunctor name) // { wrapped = type; };
|
||||
nestedTypes.elemType = type;
|
||||
};
|
||||
|
||||
# Null or value of ...
|
||||
nullOr = elemType: mkOptionType rec {
|
||||
name = "nullOr";
|
||||
|
@ -599,6 +611,7 @@ rec {
|
|||
# A value from a set of allowed ones.
|
||||
enum = values:
|
||||
let
|
||||
inherit (lib.lists) unique;
|
||||
show = v:
|
||||
if builtins.isString v then ''"${v}"''
|
||||
else if builtins.isInt v then builtins.toString v
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue