Skip to content

Commit 89e5b47

Browse files
committed
check-meta: add allowBrokenPredicate
Similar to allowUnfreePredicate, sometimes users may want to only allow specific broken packages to avoid unexpectedly building others. Some packages may be marked broken for policy reasons (lack of upstream support) or due to broken or unsupported functionality that the user may not care about. An example might be forcing ZFS to build on a newer, unsupported Kernel where compilation succeeds and the user is willing to take the risk of being unsupported.
1 parent adaa24f commit 89e5b47

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
@@ -33,15 +33,23 @@ Most unfree licenses prohibit either executing or distributing the software.
3333

3434
## Installing broken packages {#sec-allow-broken}
3535

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

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

4040
```ShellSession
4141
$ export NIXPKGS_ALLOW_BROKEN=1
4242
```
4343

44-
- For permanently allowing broken packages to be built, you may add `allowBroken = true;` to your user's configuration file, like this:
44+
- 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:
45+
46+
```nix
47+
{
48+
allowBrokenPredicate = pkg: builtins.elem (pkgs.lib.getName pkg) [ "hello" ];
49+
}
50+
```
51+
52+
- For permanently allowing all broken packages to be built, you may add `allowBroken = true;` to your user's configuration file, like this:
4553

4654
```nix
4755
{

pkgs/stdenv/generic/check-meta.nix

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

117117
isMarkedBroken = attrs: attrs.meta.broken or false;
118118

119+
# Allow granular checks to allow only some broken packages
120+
# Example:
121+
# { pkgs, ... }:
122+
# {
123+
# allowBroken = false;
124+
# allowBrokenPredicate = pkg: builtins.elem (pkgs.lib.getName pkg) [ "hello" ];
125+
# }
126+
allowBrokenPredicate = config.allowBrokenPredicate or (x: false);
127+
128+
hasDeniedBroken =
129+
attrs: (attrs.meta.broken or false) && !allowBroken && !allowBrokenPredicate attrs;
130+
119131
hasUnsupportedPlatform = pkg: !(availableOn hostPlatform pkg);
120132

121133
isMarkedInsecure = attrs: (attrs.meta.knownVulnerabilities or [ ]) != [ ];
@@ -507,7 +519,7 @@ let
507519
reason = "non-source";
508520
errormsg = "contains elements not built from source (‘${showSourceType attrs.meta.sourceProvenance}’)";
509521
}
510-
else if !allowBroken && attrs.meta.broken or false then
522+
else if hasDeniedBroken attrs then
511523
{
512524
valid = "no";
513525
reason = "broken";

0 commit comments

Comments
 (0)