Skip to content

Commit a076a60

Browse files
committed
Allow specifying allowUnfreePredicate instead of allowUnfree. The predicate will have access to the arguments of mkDerivation call. Should be an improvement for #2188
1 parent 18023bc commit a076a60

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkgs/stdenv/generic/default.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ let
1616

1717
allowUnfree = config.allowUnfree or false || builtins.getEnv "NIXPKGS_ALLOW_UNFREE" == "1";
1818

19+
# Alow granular checks to allow only some unfree packages
20+
# Example:
21+
# {pkgs, ...}:
22+
# {
23+
# allowUnfree = false;
24+
# allowUnfreePredicate = (x: pkgs.lib.hasPrefix "flashplayero-" x.name);
25+
# }
26+
allowUnfreePredicate = config.allowUnfreePredicate or (x: false);
27+
1928
allowBroken = config.allowBroken or false || builtins.getEnv "NIXPKGS_ALLOW_BROKEN" == "1";
2029

2130
unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null);
@@ -57,7 +66,7 @@ let
5766
unsafeGetAttrPos "name" attrs;
5867
pos' = if pos != null then "‘" + pos.file + ":" + toString pos.line + "’" else "«unknown-file»";
5968
in
60-
if !allowUnfree && (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l) then
69+
if !allowUnfree && (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l) && !(allowUnfreePredicate attrs) then
6170
throw ''
6271
Package ‘${attrs.name}’ in ${pos'} has an unfree license, refusing to evaluate. You can set
6372
{ nixpkgs.config.allowUnfree = true; }

0 commit comments

Comments
 (0)