Skip to content

Commit

Permalink
Merge pull request #212939 from amjoseph-nixpkgs/pr/isStatic
Browse files Browse the repository at this point in the history
meta: replace predicates with pattern over elaborated platform
  • Loading branch information
flokli authored Jan 30, 2023
2 parents b334fb7 + 9c0a341 commit 31931ff
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
11 changes: 5 additions & 6 deletions lib/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions lib/systems/inspect.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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; }; };
Expand Down Expand Up @@ -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; };
};
}
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/systemd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/generic/check-meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 31931ff

Please sign in to comment.