git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #34444 from obsidiansystems/meta-check

lib: Fix #30902

commit2fa2197a96fec6a15623bfab96b27d2b1fbe8949 authorJohn Ericson <Ericson2314@yahoo.com> dateSun 18 Mar 2018, 13:51 (9 years ago) parent38c4c3aeae19f3
7 files changed+65−22
lib/default.nix+1−1 lib/systems/default.nix+1 lib/systems/doubles.nix+2−2 lib/systems/for-meta.nix+27 pkgs/stdenv/generic/check-meta.nix+19−14 pkgs/stdenv/generic/make-derivation.nix+3−4 pkgs/top-level/release-lib.nix+12−1
lib/default.nix+1−1
@@ -47,7 +47,7 @@ let
4747 filesystem = callLibs ./filesystem.nix;
4848
4949 # back-compat aliases
50− platforms = systems.doubles;
50+ platforms = systems.forMeta;
5151
5252 inherit (builtins) add addErrorContext attrNames
5353 concatLists deepSeq elem elemAt filter genericClosure genList
lib/systems/default.nix+1
@@ -3,6 +3,7 @@
33
44rec {
55 doubles = import ./doubles.nix { inherit lib; };
6+ forMeta = import ./for-meta.nix { inherit lib; };
67 parse = import ./parse.nix { inherit lib; };
78 inspect = import ./inspect.nix { inherit lib; };
89 platforms = import ./platforms.nix { inherit lib; };
lib/systems/doubles.nix+2−2
@@ -30,14 +30,14 @@ in rec {
3030 aarch64 = filterDoubles predicates.isAarch64;
3131 x86 = filterDoubles predicates.isx86;
3232 i686 = filterDoubles predicates.isi686;
33− mips = filterDoubles predicates.isMips;
3433 x86_64 = filterDoubles predicates.isx86_64;
34+ mips = filterDoubles predicates.isMips;
3535
3636 cygwin = filterDoubles predicates.isCygwin;
3737 darwin = filterDoubles predicates.isDarwin;
3838 freebsd = filterDoubles predicates.isFreeBSD;
3939 # Should be better, but MinGW is unclear, and HURD is bit-rotted.
40− gnu = filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnu; });
40+ gnu = filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnu; });
4141 illumos = filterDoubles predicates.isSunOS;
4242 linux = filterDoubles predicates.isLinux;
4343 netbsd = filterDoubles predicates.isNetBSD;
lib/systems/for-meta.nixnew file+27
@@ -0,0 +1,27 @@
1+{ lib }:
2+let
3+ inherit (lib.systems) parse;
4+ inherit (lib.systems.inspect) patterns;
5+
6+in rec {
7+ inherit (lib.systems.doubles) all mesaPlatforms;
8+ none = [];
9+
10+ arm = [ patterns.Arm ];
11+ aarch64 = [ patterns.Aarch64 ];
12+ x86 = [ patterns.x86 ];
13+ i686 = [ patterns.i686 ];
14+ x86_64 = [ patterns.x86_64 ];
15+ mips = [ patterns.Mips ];
16+
17+ cygwin = [ patterns.Cygwin ];
18+ darwin = [ patterns.Darwin ];
19+ freebsd = [ patterns.FreeBSD ];
20+ # Should be better, but MinGW is unclear, and HURD is bit-rotted.
21+ gnu = [ { kernel = parse.kernels.linux; abi = parse.abis.gnu; } ];
22+ illumos = [ patterns.SunOS ];
23+ linux = [ patterns.Linux ];
24+ netbsd = [ patterns.NetBSD ];
25+ openbsd = [ patterns.OpenBSD ];
26+ unix = patterns.Unix; # Actually a list
27+}
pkgs/stdenv/generic/check-meta.nix+19−14
@@ -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
pkgs/stdenv/generic/make-derivation.nix+3−4
@@ -204,12 +204,11 @@ rec {
204204 });
205205
206206 validity = import ./check-meta.nix {
207− inherit lib config meta derivationArg;
208− mkDerivationArg = attrs;
207+ inherit lib config meta;
209208 # Nix itself uses the `system` field of a derivation to decide where
210209 # to build it. This is a bit confusing for cross compilation.
211− inherit (stdenv) system;
212− };
210+ inherit (stdenv) hostPlatform;
211+ } attrs;
213212
214213 # The meta attribute is passed in the resulting attribute set,
215214 # but it's not part of the actual derivation, i.e., it's not
pkgs/top-level/release-lib.nix+12−1
@@ -98,7 +98,18 @@ rec {
9898 packagePlatforms = mapAttrs (name: value:
9999 let res = builtins.tryEval (
100100 if isDerivation value then
101− value.meta.hydraPlatforms or (value.meta.platforms or [ "x86_64-linux" ])
101+ # TODO(@Ericson2314) deduplicate with `checkPlatform` in
102+ # `pkgs/stdenv/generic/check-meta.nix`.
103+ 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)
102113 else if value.recurseForDerivations or false || value.recurseForRelease or false then
103114 packagePlatforms value
104115 else