Merge pull request #212939 from amjoseph-nixpkgs/pr/isStatic

meta: replace predicates with pattern over elaborated platform
This commit is contained in:
Florian Klink 2023-01-30 21:13:15 +01:00 committed by GitHub
commit 31931ffc35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 8 deletions

View File

@ -76,20 +76,19 @@ rec {
1. (legacy) a system string.
2. (modern) a pattern for the platform `parsed` field.
2. (modern) a pattern for the entire platform structure (see `lib.systems.inspect.platformPatterns`).
3. (functional) a predicate function returning a boolean.
3. (modern) a pattern for the platform `parsed` field (see `lib.systems.inspect.patterns`).
We can inject these into a pattern for the whole of a structured platform,
and then match that.
*/
platformMatch = platform: elem:
if builtins.isFunction elem
then elem platform
else let
platformMatch = platform: elem: let
pattern =
if builtins.isString elem
then { system = elem; }
else if elem?parsed
then elem
else { parsed = elem; };
in lib.matchAttrs pattern platform;

View File

@ -7,6 +7,7 @@ let abis_ = abis; in
let abis = lib.mapAttrs (_: abi: builtins.removeAttrs abi [ "assertions" ]) abis_; in
rec {
# these patterns are to be matched against {host,build,target}Platform.parsed
patterns = rec {
isi686 = { cpu = cpuTypes.i686; };
isx86_32 = { cpu = { family = "x86"; bits = 32; }; };
@ -90,4 +91,13 @@ rec {
else matchAttrs patterns;
predicates = mapAttrs (_: matchAnyAttrs) patterns;
# these patterns are to be matched against the entire
# {host,build,target}Platform structure; they include a `parsed={}` marker so
# that `lib.meta.availableOn` can distinguish them from the patterns which
# apply only to the `parsed` field.
platformPatterns = mapAttrs (_: p: { parsed = {}; } // p) {
isStatic = { isStatic = true; };
};
}

View File

@ -714,7 +714,7 @@ stdenv.mkDerivation {
description = "A system and service manager for Linux";
license = licenses.lgpl21Plus;
platforms = platforms.linux;
badPlatforms = [ (plat: plat.isStatic) ];
badPlatforms = [ lib.systems.inspect.platformPatterns.isStatic ];
# https://github.com/systemd/systemd/issues/20600#issuecomment-912338965
broken = stdenv.hostPlatform.isStatic;
priority = 10;

View File

@ -271,7 +271,7 @@ let
sourceProvenance = listOf lib.types.attrs;
maintainers = listOf (attrsOf anything); # TODO use the maintainer type from lib/tests/maintainer-module.nix
priority = int;
platforms = listOf (oneOf [ str (attrsOf anything) (functionTo bool) ]); # see lib.meta.platformMatch
platforms = listOf (either str (attrsOf anything)); # see lib.meta.platformMatch
hydraPlatforms = listOf str;
broken = bool;
unfree = bool;