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:
Robert Hensing
2022-01-24 01:07:32 +01:00
parent ccb85a53b6
commit ba3e91ed43
3 changed files with 23 additions and 3 deletions

View File

@@ -134,6 +134,12 @@ rec {
throw "The unique option `${showOption loc}' is defined multiple times. Definition values:${showDefs defs}"
else (head defs).value;
mergeUniqueOption = { message }: loc: defs:
if length defs == 1
then (head defs).value
else assert length defs > 1;
throw "The option `${showOption loc}' is defined multiple times.\n${message}\nDefinition values:${showDefs defs}";
/* "Merge" option definitions by checking that they all have the same value. */
mergeEqualOption = loc: defs:
if defs == [] then abort "This case should never happen."