Skip to content

Commit 91c7606

Browse files
authored
check-meta: add allowBrokenPredicate (#340081)
2 parents 54a65ab + 89e5b47 commit 91c7606

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

doc/using/configuration.chapter.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,23 @@ Most unfree licenses prohibit either executing or distributing the software.
3131

3232
## Installing broken packages {#sec-allow-broken}
3333

34-
There are two ways to try compiling a package which has been marked as broken.
34+
There are several ways to try compiling a package which has been marked as broken.
3535

3636
- For allowing the build of a broken package once, you can use an environment variable for a single invocation of the nix tools:
3737

3838
```ShellSession
3939
$ export NIXPKGS_ALLOW_BROKEN=1
4040
```
4141

42-
- For permanently allowing broken packages to be built, you may add `allowBroken = true;` to your user's configuration file, like this:
42+
- For permanently allowing broken packages that match some condition to be built, you may add `allowBrokenPredicate` to your user's configuration file with the desired condition, for example:
43+
44+
```nix
45+
{
46+
allowBrokenPredicate = pkg: builtins.elem (pkgs.lib.getName pkg) [ "hello" ];
47+
}
48+
```
49+
50+
- For permanently allowing all broken packages to be built, you may add `allowBroken = true;` to your user's configuration file, like this:
4351

4452
```nix
4553
{ allowBroken = true; }

pkgs/stdenv/generic/check-meta.nix

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ let
125125

126126
isMarkedBroken = attrs: attrs.meta.broken or false;
127127

128+
# Allow granular checks to allow only some broken packages
129+
# Example:
130+
# { pkgs, ... }:
131+
# {
132+
# allowBroken = false;
133+
# allowBrokenPredicate = pkg: builtins.elem (pkgs.lib.getName pkg) [ "hello" ];
134+
# }
135+
allowBrokenPredicate = config.allowBrokenPredicate or (x: false);
136+
137+
hasDeniedBroken =
138+
attrs: (attrs.meta.broken or false) && !allowBroken && !allowBrokenPredicate attrs;
139+
128140
hasUnsupportedPlatform = pkg: !(availableOn hostPlatform pkg);
129141

130142
isMarkedInsecure = attrs: (attrs.meta.knownVulnerabilities or [ ]) != [ ];
@@ -516,7 +528,7 @@ let
516528
reason = "non-source";
517529
errormsg = "contains elements not built from source (‘${showSourceType attrs.meta.sourceProvenance}’)";
518530
}
519-
else if !allowBroken && attrs.meta.broken or false then
531+
else if hasDeniedBroken attrs then
520532
{
521533
valid = "no";
522534
reason = "broken";

0 commit comments

Comments
 (0)