Skip to content

Commit d2e4af7

Browse files
committed
stdenv: allow querying meta on disallowed packages
In the end I've chosen to do the check when evaluating the name. There were two tricky points to consider: - nix-env -qa (changes in there tend to be very slow to get released) - hydra.nixos.org #9305 (comment)
1 parent ec72f85 commit d2e4af7

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

lib/check-meta.nix

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@ let
22
lib = import ./default.nix;
33
in rec {
44

5-
# Extend a derivation with a check for brokenness, license, etc.
6-
# Throw a descriptive error when the check fails.
7-
# Note: no dependencies are checked in this step.
8-
addMetaCheck = config: meta: drv:
5+
# Extend attributes to be passed to derivation (or similar) with a check
6+
# for brokenness, license, etc. Throw a descriptive error if the check fails.
7+
# Note: no dependencies are checked in this step, but this should be done before
8+
# applying the `derivation` primitive in order to "propagate to dependants".
9+
addMetaCheckInner = config: meta: drv:
910
let
1011
name = drv.name or "«name-missing»";
1112
position = meta.position or "«unknown-file»";
1213
v = checkMetaValidity { inherit meta config; inherit (drv) system; };
1314
in
14-
if v.valid then drv
15+
# As a compromise, do the check when evaluating the name attribute;
16+
# the intention is to also catch any attempt to show in nix-env -qa,
17+
# while allowing to query meta (surprisingly even --no-name doesn't break that).
18+
drv // {
19+
name = if v.valid then drv.name
1520
else throwEvalHelp (removeAttrs v ["valid"] // { inherit name position; });
21+
};
22+
23+
# Make sure the dependencies are evaluted when accessing the name.
24+
# The input is a derivation, i.e. *after* applying the `derivation` primitive.
25+
addMetaCheckOuter = drv:
26+
drv // { name = assert drv.outPath != null; drv.name; };
1627

1728
# Throw a descriptive error message for a failed evaluation check.
1829
throwEvalHelp = { reason, errormsg, name, position }:

pkgs/stdenv/generic/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ let
169169
in
170170

171171
lib.addPassthru
172-
(derivation (lib.addMetaCheck config meta derivationArg))
172+
(lib.addMetaCheckOuter (derivation (lib.addMetaCheckInner config meta derivationArg)))
173173
( {
174174
overrideAttrs = f: mkDerivation (attrs // (f attrs));
175175
inherit meta passthru;

pkgs/top-level/release-lib.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ rec {
8585
packagePlatforms = mapAttrs (name: value:
8686
let res = builtins.tryEval (
8787
if isDerivation value then
88+
# Hopefully a reliable way to test whether the derivation evaluates,
89+
# including brokenness/license checks in any dependencies.
90+
assert value.outPath != null;
8891
value.meta.hydraPlatforms or (value.meta.platforms or [ "x86_64-linux" ])
8992
else if value.recurseForDerivations or false || value.recurseForRelease or false then
9093
packagePlatforms value

0 commit comments

Comments
 (0)