From 778419b9e6e9d82d5801b382070a81169f5920ca Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 27 Jan 2023 01:49:39 -0800 Subject: [PATCH 1/8] Revert "lib/meta.nix: platformMatch: allow predicate functions" This reverts commit b7d097438b9b0f782a707f3295d320d824810864. --- lib/meta.nix | 7 +------ pkgs/stdenv/generic/check-meta.nix | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/meta.nix b/lib/meta.nix index cdd3e1d596c0..62894aeb316b 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -78,15 +78,10 @@ rec { 2. (modern) a pattern for the platform `parsed` field. - 3. (functional) a predicate function returning a boolean. - 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; } diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 94998bbfa0fe..751e19d1681a 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; From 1690aa6858102c0986075f460f93d693c724327b Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 27 Jan 2023 02:19:30 -0800 Subject: [PATCH 2/8] lib/meta.nix: allow patterns over entire platform, not just `.parsed` --- lib/meta.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/meta.nix b/lib/meta.nix index 62894aeb316b..40d6948ebdc7 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -76,7 +76,9 @@ rec { 1. (legacy) a system string. - 2. (modern) a pattern for the platform `parsed` field. + 2. (modern) a pattern for the entire platform structure. + + 3. (modern) a pattern for the platform `parsed` field. We can inject these into a pattern for the whole of a structured platform, and then match that. @@ -85,6 +87,8 @@ rec { pattern = if builtins.isString elem then { system = elem; } + else if elem?parsed + then elem else { parsed = elem; }; in lib.matchAttrs pattern platform; From ea0bcf25053464a9f0483c3b2f411275de036e57 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 27 Jan 2023 02:19:54 -0800 Subject: [PATCH 3/8] lib/systems/inspect.nix: add platformPatterns.isStatic --- lib/systems/inspect.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index a5fed5acf2c5..65a9100f1993 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 = { + isStatic = { parsed = {}; isStatic = true; }; + }; } From a94114e70a761e346f36d4ebdef01da8fe53c778 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 27 Jan 2023 02:21:41 -0800 Subject: [PATCH 4/8] systemd: use non-function pattern for badPlatforms Closes #212925 --- pkgs/os-specific/linux/systemd/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix index fadb6a486c82..805dd9d5ba8b 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; From 6f942d4a17c11874c5d345ea3f872a0f54bce9bd Mon Sep 17 00:00:00 2001 From: Adam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com> Date: Fri, 27 Jan 2023 11:16:19 +0000 Subject: [PATCH 5/8] Update lib/meta.nix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Naïm Favier --- lib/meta.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/meta.nix b/lib/meta.nix index 40d6948ebdc7..44d2eb0ffd2f 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -76,7 +76,7 @@ rec { 1. (legacy) a system string. - 2. (modern) a pattern for the entire platform structure. + 2. (modern) a pattern for the entire platform structure (see `lib.systems.inspect.platformPatterns`). 3. (modern) a pattern for the platform `parsed` field. From 435618d9b3d47f978d397a0ea2934b2b9e0b1dd6 Mon Sep 17 00:00:00 2001 From: Adam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com> Date: Fri, 27 Jan 2023 11:16:29 +0000 Subject: [PATCH 6/8] Update lib/meta.nix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Naïm Favier --- lib/meta.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/meta.nix b/lib/meta.nix index 44d2eb0ffd2f..5fd55c4e90d6 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -78,7 +78,7 @@ rec { 2. (modern) a pattern for the entire platform structure (see `lib.systems.inspect.platformPatterns`). - 3. (modern) a pattern for the platform `parsed` field. + 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. From 009a3f1857a89c9f085b03e85410c0713a9d451f Mon Sep 17 00:00:00 2001 From: Adam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com> Date: Fri, 27 Jan 2023 11:16:35 +0000 Subject: [PATCH 7/8] Update lib/systems/inspect.nix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Naïm Favier --- lib/systems/inspect.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 65a9100f1993..104b735826b1 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -98,6 +98,6 @@ rec { # apply only to the `parsed` field. platformPatterns = { - isStatic = { parsed = {}; isStatic = true; }; + isStatic = { parsed = {}; isStatic = true; }; }; } From 9c0a3417c8defd0b5f4b592659c88c978f8b36b6 Mon Sep 17 00:00:00 2001 From: Adam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com> Date: Fri, 27 Jan 2023 11:56:20 +0000 Subject: [PATCH 8/8] Update lib/systems/inspect.nix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Naïm Favier --- lib/systems/inspect.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 104b735826b1..f823989f83ec 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -97,7 +97,7 @@ rec { # that `lib.meta.availableOn` can distinguish them from the patterns which # apply only to the `parsed` field. - platformPatterns = { - isStatic = { parsed = {}; isStatic = true; }; + platformPatterns = mapAttrs (_: p: { parsed = {}; } // p) { + isStatic = { isStatic = true; }; }; }