From c546655fb0fcc8673fe94287daee677fe484ded7 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Thu, 28 May 2026 13:28:13 -0400 Subject: [PATCH] check-meta: only take hostPlatform for functions requiring it By doing this, we can cache the rest of the file, including the import of problems.nix. This allows genCheckProblems to be cached on every bootstrapping stage, and not re-called each time. --- .../linux/minimal-bootstrap/default.nix | 6 ++++- .../linux/minimal-bootstrap/utils.nix | 9 +++++-- pkgs/stdenv/generic/check-meta-test.nix | 2 +- pkgs/stdenv/generic/check-meta.nix | 24 ++++++++++++++----- pkgs/stdenv/generic/make-derivation.nix | 19 ++++++++------- pkgs/stdenv/linux/stage0.nix | 2 +- pkgs/top-level/all-packages.nix | 2 +- 7 files changed, 43 insertions(+), 21 deletions(-) diff --git a/pkgs/os-specific/linux/minimal-bootstrap/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/default.nix index a8c44d52fc5c..dae72f79852a 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/default.nix @@ -361,7 +361,11 @@ lib.makeScope gnutar = gnutar-latest; }; - inherit (callPackage ./utils.nix { }) derivationWithMeta writeTextFile writeText; + inherit (callPackage ./utils.nix { inherit hostPlatform; }) + derivationWithMeta + writeTextFile + writeText + ; test = kaem.runCommand "minimal-bootstrap-test" { } ( '' echo ${bash.tests.get-version} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/utils.nix b/pkgs/os-specific/linux/minimal-bootstrap/utils.nix index 180d55a91494..96e983f537f8 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/utils.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/utils.nix @@ -6,7 +6,12 @@ kaem, mescc-tools-extra, checkMeta, + hostPlatform, }: +let + assertValidity = checkMeta.assertValidity hostPlatform; + commonMeta = checkMeta.commonMeta hostPlatform; +in rec { maybeContentAddressed = lib.optionalAttrs config.contentAddressedByDefault { __contentAddressed = true; @@ -18,8 +23,8 @@ rec { attrs: let passthru = attrs.passthru or { }; - validity = checkMeta.assertValidity { inherit meta attrs; }; - meta = checkMeta.commonMeta { inherit validity attrs; }; + validity = assertValidity { inherit meta attrs; }; + meta = commonMeta { inherit validity attrs; }; baseDrv = derivation ( { inherit (buildPlatform) system; diff --git a/pkgs/stdenv/generic/check-meta-test.nix b/pkgs/stdenv/generic/check-meta-test.nix index bbd24acf8614..336c6bd5a78e 100644 --- a/pkgs/stdenv/generic/check-meta-test.nix +++ b/pkgs/stdenv/generic/check-meta-test.nix @@ -47,7 +47,7 @@ let checkMeta = testPkgs.callPackage ./check-meta.nix { }; tryEval = expression: builtins.tryEval (builtins.deepSeq expression expression); actual = tryEval ( - checkMeta.assertValidity { + checkMeta.assertValidity pkgs.stdenv.hostPlatform { meta = pkg.meta; attrs = pkg; } diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index ac5ff3c0a6f1..70c009c3e83a 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -4,7 +4,6 @@ { lib, config, - hostPlatform, }: let @@ -122,6 +121,7 @@ let # Logical inversion of meta.availableOn for hostPlatform hasUnsupportedPlatform = + hostPlatform: let inherit (hostPlatform) system; # in almost all cases, meta.platforms is a simple list of strings, and we @@ -416,6 +416,10 @@ let # !!! reason strings are hardcoded into OfBorg, make sure to keep them in sync # Along with a boolean flag for each reason checkValidity = + hostPlatform: + let + hasUnsupportedPlatform' = hasUnsupportedPlatform hostPlatform; + in attrs: if !attrs ? meta then null @@ -458,7 +462,7 @@ let msg = "contains elements not built from source (‘${showSourceType attrs.meta.sourceProvenance}’)"; remediation = remediate_allowlist "NonSource" (remediate_predicate "allowNonSourcePredicate" attrs); } - else if hasUnsupportedPlatform attrs && !allowUnsupportedSystem then + else if hasUnsupportedPlatform' attrs && !allowUnsupportedSystem then let toPretty' = toPretty { allowPrettyValues = true; @@ -518,9 +522,13 @@ let # passed to the builder and is not a dependency. But since we # include it in the result, it *is* available to nix-env for queries. # Example: - # meta = checkMeta.commonMeta { inherit validity attrs pos references; }; - # validity = checkMeta.assertValidity { inherit meta attrs; }; + # meta = checkMeta.commonMeta hostPlatform { inherit validity attrs pos references; }; + # validity = checkMeta.assertValidity hostPlatform { inherit meta attrs; }; commonMeta = + hostPlatform: + let + hasUnsupportedPlatform' = hasUnsupportedPlatform hostPlatform; + in { validity, attrs, @@ -659,7 +667,7 @@ let # Expose the result of the checks for everyone to see. unfree = hasUnfreeLicense attrs; broken = isMarkedBroken attrs; - unsupported = hasUnsupportedPlatform attrs; + unsupported = hasUnsupportedPlatform' attrs; insecure = isMarkedInsecure attrs; available = @@ -705,9 +713,13 @@ let builtins.seq (foldl' giveWarning null warnings) withError; assertValidity = + hostPlatform: + let + checkValidity' = checkValidity hostPlatform; + in { meta, attrs }: let - invalid = checkValidity attrs; + invalid = checkValidity' attrs; problems = checkProblems attrs; in if isNull invalid then diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 85802f86160c..89d413931c1b 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -189,6 +189,9 @@ let structuredAttrsByDefault = config.structuredAttrsByDefault or false; inherit (config) enableParallelBuildingByDefault contentAddressedByDefault; userHook = config.stdenv.userHook or null; + checkMeta = import ./check-meta.nix { + inherit lib config; + }; in stdenv: @@ -196,6 +199,11 @@ let inherit (import ../../build-support/lib/cmake.nix { inherit lib stdenv; }) makeCMakeFlags; inherit (import ../../build-support/lib/meson.nix { inherit lib stdenv; }) makeMesonFlags; + # Nix itself uses the `system` field of a derivation to decide where + # to build it. This is a bit confusing for cross compilation. + commonMeta = checkMeta.commonMeta hostPlatform; + assertValidity = checkMeta.assertValidity hostPlatform; + /** This function creates a derivation, and returns it in the form of a [package attribute set](https://nix.dev/manual/nix/latest/glossary#package-attribute-set) that refers to the derivation's outputs. @@ -216,13 +224,6 @@ let */ mkDerivation = fnOrAttrs: makeDerivationExtensible (toFunction fnOrAttrs); - checkMeta = import ./check-meta.nix { - inherit lib config; - # Nix itself uses the `system` field of a derivation to decide where - # to build it. This is a bit confusing for cross compilation. - inherit (stdenv) hostPlatform; - }; - # Based off lib.makeExtensible, with modifications: makeDerivationExtensible = rattrs: @@ -971,7 +972,7 @@ let } ); - meta = checkMeta.commonMeta { + meta = commonMeta { inherit validity attrs pos; references = attrs.nativeBuildInputs or [ ] @@ -979,7 +980,7 @@ let ++ attrs.propagatedNativeBuildInputs or [ ] ++ attrs.propagatedBuildInputs or [ ]; }; - validity = checkMeta.assertValidity { inherit meta attrs; }; + validity = assertValidity { inherit meta attrs; }; checkedEnv = let diff --git a/pkgs/stdenv/linux/stage0.nix b/pkgs/stdenv/linux/stage0.nix index 53e5605d65ef..9fa4bb162efd 100644 --- a/pkgs/stdenv/linux/stage0.nix +++ b/pkgs/stdenv/linux/stage0.nix @@ -23,7 +23,7 @@ if minbootSupported then system = localSystem; inherit (config) rewriteURL; }; - checkMeta = callPackage ../generic/check-meta.nix { hostPlatform = localSystem; }; + checkMeta = callPackage ../generic/check-meta.nix { }; } ); compilerPackage = diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2f9e52e654f5..2723b93b644a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8424,7 +8424,7 @@ with pkgs; inherit (stdenv.buildPlatform) system; inherit (config) rewriteURL; }; - checkMeta = callPackage ../stdenv/generic/check-meta.nix { inherit (stdenv) hostPlatform; }; + checkMeta = callPackage ../stdenv/generic/check-meta.nix { }; } ); minimal-bootstrap-sources =