diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2018-03-19 18:03:46 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2018-03-19 19:29:16 -0400 |
commit | e547bd0dc419cdbe2e8d8440224b252f723590ab (patch) | |
tree | 56bcf02f80daba865e1aa7e5c9cf9b65ad21a62d | |
parent | eae19f3c28503a8623b0fee10bfb0b3322122637 (diff) | |
download | nixpkgs-e547bd0dc419cdbe2e8d8440224b252f723590ab.tar nixpkgs-e547bd0dc419cdbe2e8d8440224b252f723590ab.tar.gz nixpkgs-e547bd0dc419cdbe2e8d8440224b252f723590ab.tar.bz2 nixpkgs-e547bd0dc419cdbe2e8d8440224b252f723590ab.tar.lz nixpkgs-e547bd0dc419cdbe2e8d8440224b252f723590ab.tar.xz nixpkgs-e547bd0dc419cdbe2e8d8440224b252f723590ab.tar.zst nixpkgs-e547bd0dc419cdbe2e8d8440224b252f723590ab.zip |
lib: Factor in tiny bit of `meta.platform` checking
I need it in stdenv and release-lib, so that seems motivation enough.
-rw-r--r-- | lib/meta.nix | 19 | ||||
-rw-r--r-- | pkgs/stdenv/generic/check-meta.nix | 6 | ||||
-rw-r--r-- | pkgs/top-level/release-lib.nix | 16 |
3 files changed, 26 insertions, 15 deletions
diff --git a/lib/meta.nix b/lib/meta.nix index 07b1710fff7..199030c103a 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -67,4 +67,23 @@ rec { */ 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; } diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 444bad84d8d..6a8d97458e5 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -173,10 +173,8 @@ let 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 []; - checkPlatform = attrs: let - raw = 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; + checkPlatform = attrs: + lib.any (lib.meta.platformMatch hostPlatform) attrs.meta.platforms; # Check if a derivation is valid, that is whether it passes checks for # e.g brokenness or license. diff --git a/pkgs/top-level/release-lib.nix b/pkgs/top-level/release-lib.nix index e377ca30f3a..dbeb13d4bd3 100644 --- a/pkgs/top-level/release-lib.nix +++ b/pkgs/top-level/release-lib.nix @@ -98,18 +98,12 @@ rec { packagePlatforms = mapAttrs (name: value: let res = builtins.tryEval ( if isDerivation value then - # TODO(@Ericson2314) deduplicate with `checkPlatform` in - # `pkgs/stdenv/generic/check-meta.nix`. value.meta.hydraPlatforms or (let - raw = value.meta.platforms or [ "x86_64-linux" ]; - toPattern = x: if builtins.isString x - then { system = x; } - else { parsed = x; }; - uniform = map toPattern raw; - pred = hostPlatform: - lib.any (pat: lib.matchAttrs pat hostPlatform) uniform; - pred' = system: pred (lib.systems.elaborate { inherit system; }); - in lib.filter pred' supportedSystems) + linuxDefaulted = value.meta.platforms or [ "x86_64-linux" ]; + pred = system: lib.any + (lib.meta.platformMatch (lib.systems.elaborate { inherit system; })) + linuxDefaulted; + in lib.filter pred supportedSystems) else if value.recurseForDerivations or false || value.recurseForRelease or false then packagePlatforms value else |