diff --git a/lib/lists.nix b/lib/lists.nix index a04b1b27893..6a8fd8a1840 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -477,4 +477,12 @@ rec { */ subtractLists = e: filter (x: !(elem x e)); + /* Test if two lists have no common element. + It should be slightly more efficient than (intersectLists a b == []) + */ + mutuallyExclusive = a: b: + (builtins.length a) == 0 || + (!(builtins.elem (builtins.head a) b) && + mutuallyExclusive (builtins.tail a) b); + } diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 065f4fb508d..690b917b376 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -45,13 +45,8 @@ let throw ''‘${showLicense license}’ is not an attribute of lib.licenses'' ) list; - mutuallyExclusive = a: b: - (builtins.length a) == 0 || - (!(builtins.elem (builtins.head a) b) && - mutuallyExclusive (builtins.tail a) b); - areLicenseListsValid = - if mutuallyExclusive whitelist blacklist then + if lib.mutuallyExclusive whitelist blacklist then assert onlyLicenses whitelist; assert onlyLicenses blacklist; true else throw "whitelistedLicenses and blacklistedLicenses are not mutually exclusive.";