diff --git a/lib/meta.nix b/lib/meta.nix index cdd3e1d596c03..5fd55c4e90d69 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -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; diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index b40a82b3321e8..c3ed528682657 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -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; }; + }; } diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix index fadb6a486c82d..805dd9d5ba8bd 100644 --- a/pkgs/os-specific/linux/systemd/default.nix +++ b/pkgs/os-specific/linux/systemd/default.nix @@ -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; diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 94998bbfa0fee..751e19d1681ae 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -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;