git.iko.soy/typeable/nixpkgs
on master help sign in
lib, stdenv: Check `meta.platforms` against host platform and be open world

First, we need check against the host platform, not the build platform. That's simple enough. Second, we move away from exahustive finite case analysis (i.e. exhaustively listing all platforms the package builds on). That only work in a closed-world setting, where we know all platforms we might build one. But with cross compilation, we may be building for arbitrary platforms, So we need fancier filters. This is the closed world to open world change. The solution is instead of having a list of systems (strings in the form "foo-bar"), we have a list of of systems or "patterns", i.e. attributes that partially match the output of the parsers in `lib.systems.parse`. The "check meta" logic treats the systems strings as an exact whitelist just as before, but treats the patterns as a fuzzy whitelist, intersecting the actual `hostPlatform` with the pattern and then checking for equality. (This is done using `matchAttrs`). The default convenience lists for `meta.platforms` are now changed to be lists of patterns (usually a single pattern) in `lib/systems/for-meta.nix` for maximum flexibility under this new system. Fixes #30902

commitc26252af3e8a102e8ac7ab67ae3ceb2c19845cac authorJohn Ericson <John.Ericson@Obsidian.Systems> dateWed 31 Jan 2018, 00:11 (9 years ago) parent4c52e34
6 files changed+41−8
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+9−4 pkgs/stdenv/generic/make-derivation.nix+1−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+9−4
@@ -1,7 +1,7 @@
11# Checks derivation meta and attrs for problems (like brokenness,
22# licenses, etc).
33
4−{ lib, config, system, meta }:
4+{ lib, config, hostPlatform, meta }:
55
66let
77 # See discussion at https://github.com/NixOS/nixpkgs/pull/25304#issuecomment-298385426
@@ -144,7 +144,7 @@ let
144144 license = either (listOf lib.types.attrs) (either lib.types.attrs str);
145145 maintainers = listOf str;
146146 priority = int;
147− platforms = listOf str;
147+ platforms = listOf (either str lib.systems.parsed.types.system);
148148 hydraPlatforms = listOf str;
149149 broken = bool;
150150
@@ -173,6 +173,11 @@ 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;
180+
176181 # Check if a derivation is valid, that is whether it passes checks for
177182 # e.g brokenness or license.
178183 #
@@ -186,8 +191,8 @@ let
186191 { valid = false; reason = "blacklisted"; errormsg = "has a blacklisted license (‘${showLicense attrs.meta.license}’)"; }
187192 else if !allowBroken && attrs.meta.broken or false then
188193 { valid = false; reason = "broken"; errormsg = "is marked as broken"; }
189− else if !allowUnsupportedSystem && !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem system attrs.meta.platforms then
190− { 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}’"; }
191196 else if !(hasAllowedInsecure attrs) then
192197 { valid = false; reason = "insecure"; errormsg = "is marked as insecure"; }
193198 else let res = checkMeta (attrs.meta or {}); in if res != [] then
pkgs/stdenv/generic/make-derivation.nix+1−1
@@ -207,7 +207,7 @@ rec {
207207 inherit lib config meta;
208208 # Nix itself uses the `system` field of a derivation to decide where
209209 # to build it. This is a bit confusing for cross compilation.
210− inherit (stdenv) system;
210+ inherit (stdenv) hostPlatform;
211211 } attrs;
212212
213213 # The meta attribute is passed in the resulting attribute set,