lib: Factor in tiny bit of meta.platform
checking
I need it in stdenv and release-lib, so that seems motivation enough.
This commit is contained in:
parent
eae19f3c28
commit
e547bd0dc4
19
lib/meta.nix
19
lib/meta.nix
@ -67,4 +67,23 @@ rec {
|
|||||||
*/
|
*/
|
||||||
hiPrioSet = set: mapDerivationAttrset hiPrio set;
|
hiPrioSet = set: mapDerivationAttrset hiPrio set;
|
||||||
|
|
||||||
|
|
||||||
|
/* Check to see if a platform is matched by the given `meta.platforms`
|
||||||
|
element.
|
||||||
|
|
||||||
|
A `meta.platform` pattern is either
|
||||||
|
|
||||||
|
1. (legacy) a system string.
|
||||||
|
|
||||||
|
2. (modern) a pattern for the platform `parsed` field.
|
||||||
|
|
||||||
|
We can inject these into a patten for the whole of a structured platform,
|
||||||
|
and then match that.
|
||||||
|
*/
|
||||||
|
platformMatch = platform: elem: let
|
||||||
|
pattern =
|
||||||
|
if builtins.isString elem
|
||||||
|
then { system = elem; }
|
||||||
|
else { parsed = elem; };
|
||||||
|
in lib.matchAttrs pattern platform;
|
||||||
}
|
}
|
||||||
|
@ -173,10 +173,8 @@ let
|
|||||||
else "key '${k}' is unrecognized; expected one of: \n\t [${lib.concatMapStringsSep ", " (x: "'${x}'") (lib.attrNames metaTypes)}]";
|
else "key '${k}' is unrecognized; expected one of: \n\t [${lib.concatMapStringsSep ", " (x: "'${x}'") (lib.attrNames metaTypes)}]";
|
||||||
checkMeta = meta: if shouldCheckMeta then lib.remove null (lib.mapAttrsToList checkMetaAttr meta) else [];
|
checkMeta = meta: if shouldCheckMeta then lib.remove null (lib.mapAttrsToList checkMetaAttr meta) else [];
|
||||||
|
|
||||||
checkPlatform = attrs: let
|
checkPlatform = attrs:
|
||||||
raw = attrs.meta.platforms;
|
lib.any (lib.meta.platformMatch hostPlatform) attrs.meta.platforms;
|
||||||
uniform = map (x: if builtins.isString x then { system = x; } else { parsed = x; }) raw;
|
|
||||||
in lib.any (pat: lib.matchAttrs pat hostPlatform) uniform;
|
|
||||||
|
|
||||||
# Check if a derivation is valid, that is whether it passes checks for
|
# Check if a derivation is valid, that is whether it passes checks for
|
||||||
# e.g brokenness or license.
|
# e.g brokenness or license.
|
||||||
|
@ -98,18 +98,12 @@ rec {
|
|||||||
packagePlatforms = mapAttrs (name: value:
|
packagePlatforms = mapAttrs (name: value:
|
||||||
let res = builtins.tryEval (
|
let res = builtins.tryEval (
|
||||||
if isDerivation value then
|
if isDerivation value then
|
||||||
# TODO(@Ericson2314) deduplicate with `checkPlatform` in
|
|
||||||
# `pkgs/stdenv/generic/check-meta.nix`.
|
|
||||||
value.meta.hydraPlatforms or (let
|
value.meta.hydraPlatforms or (let
|
||||||
raw = value.meta.platforms or [ "x86_64-linux" ];
|
linuxDefaulted = value.meta.platforms or [ "x86_64-linux" ];
|
||||||
toPattern = x: if builtins.isString x
|
pred = system: lib.any
|
||||||
then { system = x; }
|
(lib.meta.platformMatch (lib.systems.elaborate { inherit system; }))
|
||||||
else { parsed = x; };
|
linuxDefaulted;
|
||||||
uniform = map toPattern raw;
|
in lib.filter pred supportedSystems)
|
||||||
pred = hostPlatform:
|
|
||||||
lib.any (pat: lib.matchAttrs pat hostPlatform) uniform;
|
|
||||||
pred' = system: pred (lib.systems.elaborate { inherit system; });
|
|
||||||
in lib.filter pred' supportedSystems)
|
|
||||||
else if value.recurseForDerivations or false || value.recurseForRelease or false then
|
else if value.recurseForDerivations or false || value.recurseForRelease or false then
|
||||||
packagePlatforms value
|
packagePlatforms value
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user