@@ -1,11 +1,9 @@
11# Checks derivation meta and attrs for problems (like brokenness,
22# licenses, etc).
33
4−{ lib, config, system, meta, derivationArg, mkDerivationArg }:
4+{ lib, config, hostPlatform, meta }:
55
66let
7− attrs = mkDerivationArg; # TODO: probably get rid of passing this one
8−
97 # See discussion at https://github.com/NixOS/nixpkgs/pull/25304#issuecomment-298385426
108 # for why this defaults to false, but I (@copumpkin) want to default it to true soon.
119 shouldCheckMeta = config.checkMeta or false;
@@ -123,7 +121,7 @@ let
123121
124122 '';
125123
126− handleEvalIssue = { reason , errormsg ? "" }:
124+ handleEvalIssue = attrs: { reason , errormsg ? "" }:
127125 let
128126 msg = ''
129127 Package ‘${attrs.name or "«name-missing»"}’ in ${pos_str} ${errormsg}, refusing to evaluate.
@@ -146,7 +144,7 @@ let
146144 license = either (listOf lib.types.attrs) (either lib.types.attrs str);
147145 maintainers = listOf (attrsOf str);
148146 priority = int;
149− platforms = listOf str;
147+ platforms = listOf (either str lib.systems.parsed.types.system);
150148 hydraPlatforms = listOf str;
151149 broken = bool;
152150
@@ -175,6 +173,11 @@ let
175173 else "key '${k}' is unrecognized; expected one of: \n\t [${lib.concatMapStringsSep ", " (x: "'${x}'") (lib.attrNames metaTypes)}]";
176174 checkMeta = meta: if shouldCheckMeta then lib.remove null (lib.mapAttrsToList checkMetaAttr meta) else [];
177175
176+ checkPlatform = attrs: let
177+ raw = attrs.meta.platforms;
178+ uniform = map (x: if builtins.isString x then { system = x; } else { parsed = x; }) raw;
179+ in lib.any (pat: lib.matchAttrs pat hostPlatform) uniform;
180+
178181 # Check if a derivation is valid, that is whether it passes checks for
179182 # e.g brokenness or license.
180183 #
@@ -188,19 +191,21 @@ let
188191 { valid = false; reason = "blacklisted"; errormsg = "has a blacklisted license (‘${showLicense attrs.meta.license}’)"; }
189192 else if !allowBroken && attrs.meta.broken or false then
190193 { valid = false; reason = "broken"; errormsg = "is marked as broken"; }
191− else if !allowUnsupportedSystem && !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem system attrs.meta.platforms then
192− { valid = false; reason = "broken"; errormsg = "is not supported on ‘${system}’"; }
194+ else if !allowUnsupportedSystem && !allowBroken && attrs.meta.platforms or null != null && !(checkPlatform attrs) then
195+ { valid = false; reason = "broken"; errormsg = "is not supported on ‘${hostPlatform.config}’"; }
193196 else if !(hasAllowedInsecure attrs) then
194197 { valid = false; reason = "insecure"; errormsg = "is marked as insecure"; }
195198 else let res = checkMeta (attrs.meta or {}); in if res != [] then
196199 { valid = false; reason = "unknown-meta"; errormsg = "has an invalid meta attrset:${lib.concatMapStrings (x: "\n\t - " + x) res}"; }
197200 else { valid = true; };
198201
199− validity = checkValidity attrs;
202+ assertValidity = attrs: let
203+ validity = checkValidity attrs;
204+ in validity // {
205+ # Throw an error if trying to evaluate an non-valid derivation
206+ handled = if !validity.valid
207+ then handleEvalIssue attrs (removeAttrs validity ["valid"])
208+ else true;
209+ };
200210
201−in validity // {
202− # Throw an error if trying to evaluate an non-valid derivation
203− handled = if !validity.valid
204− then handleEvalIssue (removeAttrs validity ["valid"])
205− else true;
206−}
211+in assertValidity