git.iko.soy/typeable/nixpkgs
on master help sign in
lib: Factor in tiny bit of `meta.platform` checking

I need it in stdenv and release-lib, so that seems motivation enough.

commite547bd0dc419cdbe2e8d8440224b252f723590ab authorJohn Ericson <John.Ericson@Obsidian.Systems> dateMon 19 Mar 2018, 18:03 (9 years ago) parenteae19f3
3 files changed+26−15
lib/meta.nix+19 pkgs/stdenv/generic/check-meta.nix+2−4 pkgs/top-level/release-lib.nix+5−11
lib/meta.nix+19
@@ -67,4 +67,23 @@ rec {
6767 */
6868 hiPrioSet = set: mapDerivationAttrset hiPrio set;
6969
70+
71+ /* Check to see if a platform is matched by the given `meta.platforms`
72+ element.
73+
74+ A `meta.platform` pattern is either
75+
76+ 1. (legacy) a system string.
77+
78+ 2. (modern) a pattern for the platform `parsed` field.
79+
80+ We can inject these into a patten for the whole of a structured platform,
81+ and then match that.
82+ */
83+ platformMatch = platform: elem: let
84+ pattern =
85+ if builtins.isString elem
86+ then { system = elem; }
87+ else { parsed = elem; };
88+ in lib.matchAttrs pattern platform;
7089}
pkgs/stdenv/generic/check-meta.nix+2−4
@@ -173,10 +173,8 @@ let
173173 else "key '${k}' is unrecognized; expected one of: \n\t [${lib.concatMapStringsSep ", " (x: "'${x}'") (lib.attrNames metaTypes)}]";
174174 checkMeta = meta: if shouldCheckMeta then lib.remove null (lib.mapAttrsToList checkMetaAttr meta) else [];
175175
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;
176+ checkPlatform = attrs:
177+ lib.any (lib.meta.platformMatch hostPlatform) attrs.meta.platforms;
180178
181179 # Check if a derivation is valid, that is whether it passes checks for
182180 # e.g brokenness or license.
pkgs/top-level/release-lib.nix+5−11
@@ -98,18 +98,12 @@ rec {
9898 packagePlatforms = mapAttrs (name: value:
9999 let res = builtins.tryEval (
100100 if isDerivation value then
101− # TODO(@Ericson2314) deduplicate with `checkPlatform` in
102− # `pkgs/stdenv/generic/check-meta.nix`.
103101 value.meta.hydraPlatforms or (let
104− raw = value.meta.platforms or [ "x86_64-linux" ];
105− toPattern = x: if builtins.isString x
106− then { system = x; }
107− else { parsed = x; };
108− uniform = map toPattern raw;
109− pred = hostPlatform:
110− lib.any (pat: lib.matchAttrs pat hostPlatform) uniform;
111− pred' = system: pred (lib.systems.elaborate { inherit system; });
112− in lib.filter pred' supportedSystems)
102+ linuxDefaulted = value.meta.platforms or [ "x86_64-linux" ];
103+ pred = system: lib.any
104+ (lib.meta.platformMatch (lib.systems.elaborate { inherit system; }))
105+ linuxDefaulted;
106+ in lib.filter pred supportedSystems)
113107 else if value.recurseForDerivations or false || value.recurseForRelease or false then
114108 packagePlatforms value
115109 else