nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

lib: Factor in tiny bit of `meta.platform` checking

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

+26 -15
+19
lib/meta.nix
··· 67 67 */ 68 68 hiPrioSet = set: mapDerivationAttrset hiPrio set; 69 69 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; 70 89 }
+2 -4
pkgs/stdenv/generic/check-meta.nix
··· 173 173 else "key '${k}' is unrecognized; expected one of: \n\t [${lib.concatMapStringsSep ", " (x: "'${x}'") (lib.attrNames metaTypes)}]"; 174 174 checkMeta = meta: if shouldCheckMeta then lib.remove null (lib.mapAttrsToList checkMetaAttr meta) else []; 175 175 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; 180 178 181 179 # Check if a derivation is valid, that is whether it passes checks for 182 180 # e.g brokenness or license.
+5 -11
pkgs/top-level/release-lib.nix
··· 98 98 packagePlatforms = mapAttrs (name: value: 99 99 let res = builtins.tryEval ( 100 100 if isDerivation value then 101 - # TODO(@Ericson2314) deduplicate with `checkPlatform` in 102 - # `pkgs/stdenv/generic/check-meta.nix`. 103 101 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) 113 107 else if value.recurseForDerivations or false || value.recurseForRelease or false then 114 108 packagePlatforms value 115 109 else