Skip to content

Commit

Permalink
stdenv: allow querying meta on disallowed packages
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
vcunat committed Jan 29, 2017
1 parent ec72f85 commit d2e4af7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
21 changes: 16 additions & 5 deletions lib/check-meta.nix
Expand Up @@ -2,17 +2,28 @@ let
lib = import ./default.nix;
in rec {

# Extend a derivation with a check for brokenness, license, etc.
# Throw a descriptive error when the check fails.
# Note: no dependencies are checked in this step.
addMetaCheck = config: meta: drv:
# Extend attributes to be passed to derivation (or similar) with a check
# for brokenness, license, etc. Throw a descriptive error if the check fails.
# Note: no dependencies are checked in this step, but this should be done before
# applying the `derivation` primitive in order to "propagate to dependants".
addMetaCheckInner = config: meta: drv:
let
name = drv.name or "«name-missing»";
position = meta.position or "«unknown-file»";
v = checkMetaValidity { inherit meta config; inherit (drv) system; };
in
if v.valid then drv
# As a compromise, do the check when evaluating the name attribute;
# the intention is to also catch any attempt to show in nix-env -qa,
# while allowing to query meta (surprisingly even --no-name doesn't break that).
drv // {
name = if v.valid then drv.name
else throwEvalHelp (removeAttrs v ["valid"] // { inherit name position; });
};

# Make sure the dependencies are evaluted when accessing the name.
# The input is a derivation, i.e. *after* applying the `derivation` primitive.
addMetaCheckOuter = drv:
drv // { name = assert drv.outPath != null; drv.name; };

# Throw a descriptive error message for a failed evaluation check.
throwEvalHelp = { reason, errormsg, name, position }:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/generic/default.nix
Expand Up @@ -169,7 +169,7 @@ let
in

lib.addPassthru
(derivation (lib.addMetaCheck config meta derivationArg))
(lib.addMetaCheckOuter (derivation (lib.addMetaCheckInner config meta derivationArg)))
( {
overrideAttrs = f: mkDerivation (attrs // (f attrs));
inherit meta passthru;
Expand Down
3 changes: 3 additions & 0 deletions pkgs/top-level/release-lib.nix
Expand Up @@ -85,6 +85,9 @@ rec {
packagePlatforms = mapAttrs (name: value:
let res = builtins.tryEval (
if isDerivation value then
# Hopefully a reliable way to test whether the derivation evaluates,
# including brokenness/license checks in any dependencies.
assert value.outPath != null;
value.meta.hydraPlatforms or (value.meta.platforms or [ "x86_64-linux" ])
else if value.recurseForDerivations or false || value.recurseForRelease or false then
packagePlatforms value
Expand Down

0 comments on commit d2e4af7

Please sign in to comment.