diff options
author | Robert Hensing <robert@roberthensing.nl> | 2022-01-24 01:07:32 +0100 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2022-01-24 16:14:55 +0100 |
commit | ba3e91ed43c05a4a0984a6faa948949612fd113c (patch) | |
tree | d749b14475b3a7e735f23d8d876fcd30532c99b4 /lib/options.nix | |
parent | ccb85a53b6a496984073227fd8c4d4c58889f421 (diff) | |
download | nixpkgs-ba3e91ed43c05a4a0984a6faa948949612fd113c.tar nixpkgs-ba3e91ed43c05a4a0984a6faa948949612fd113c.tar.gz nixpkgs-ba3e91ed43c05a4a0984a6faa948949612fd113c.tar.bz2 nixpkgs-ba3e91ed43c05a4a0984a6faa948949612fd113c.tar.lz nixpkgs-ba3e91ed43c05a4a0984a6faa948949612fd113c.tar.xz nixpkgs-ba3e91ed43c05a4a0984a6faa948949612fd113c.tar.zst nixpkgs-ba3e91ed43c05a4a0984a6faa948949612fd113c.zip |
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.
Diffstat (limited to 'lib/options.nix')
-rw-r--r-- | lib/options.nix | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/options.nix b/lib/options.nix index 53001a3113f..44ec335545c 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -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." |