From 7e851e1cf52234d0b5e53a6dcbb7f7fa702df7b0 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Tue, 12 Aug 2025 09:07:52 +0800 Subject: [PATCH] buildEnv: take derivationArgs --- pkgs/build-support/buildenv/default.nix | 47 ++++++++++++++++--------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/pkgs/build-support/buildenv/default.nix b/pkgs/build-support/buildenv/default.nix index 3e794d492cc6..996034a01bb9 100644 --- a/pkgs/build-support/buildenv/default.nix +++ b/pkgs/build-support/buildenv/default.nix @@ -21,6 +21,9 @@ lib.makeOverridable ( lib.extendMkDerivation { constructDrv = stdenvNoCC.mkDerivation; excludeDrvArgNames = [ + # Override these arguments directly + "derivationArgs" + # `meta.outputsToInstall` and `extraOutputsToInstall` does not necessarily include the first # element of outputs, while the outPath of the latter will be the string-interpolated result. # Exclude to prevent unexpected context. @@ -65,19 +68,31 @@ lib.makeOverridable ( # Shell commands to run after building the symlink tree. postBuild ? "", - # Additional inputs - nativeBuildInputs ? [ ], # Handy e.g. if using makeWrapper in `postBuild`. - buildInputs ? [ ], - passthru ? { }, meta ? { }, - # Placeholder arguments + # Additional stdenv.mkDerivation arguments + # such as nativeBuildInputs/buildInputs for postBuild dependencies. + derivationArgs ? { }, + + # Placeholder name arguments. name ? null, pname ? null, version ? null, - }: + + # `stdenv.mkDerivation` args before introducing derivationArgs. + nativeBuildInputs ? null, + buildInputs ? null, + }@args: let + compatArgs = + lib.optionalAttrs (args ? nativeBuildInputs) { + inherit nativeBuildInputs; + } + // lib.optionalAttrs (args ? buildInputs) { + inherit buildInputs; + }; + chosenOutputs = map (drv: { paths = # First add the usual output(s): respect if user has chosen explicitly, @@ -106,7 +121,9 @@ lib.makeOverridable ( (lib.remove null) ]; in - { + compatArgs + // derivationArgs + // { inherit extraOutputsToInstall manifest @@ -118,19 +135,19 @@ lib.makeOverridable ( pathsToLink extraPrefix postBuild - nativeBuildInputs - buildInputs ; pathsToLinkJSON = builtins.toJSON pathsToLink; pkgs = builtins.toJSON chosenOutputs; extraPathsFrom = lib.optionalString finalAttrs.includeClosures (writeClosure pathsForClosure); - preferLocalBuild = true; - allowSubstitutes = false; + + preferLocalBuild = derivationArgs.preferLocalBuild or true; + allowSubstitutes = derivationArgs.allowSubstitutes or false; passAsFile = [ "buildCommand" ] # XXX: The size is somewhat arbitrary - ++ lib.optional (lib.stringLength finalAttrs.pkgs >= 128 * 1024) "pkgs"; + ++ lib.optional (lib.stringLength finalAttrs.pkgs >= 128 * 1024) "pkgs" + ++ derivationArgs.passAsFile or [ ]; buildCommand = '' ${buildPackages.perl}/bin/perl -w ${builder} @@ -138,10 +155,8 @@ lib.makeOverridable ( ''; passthru = { - # Attributes to override from passthru - inherit - paths - ; + # The `paths` attribute is referenced and overridden from passthru + inherit paths; } // passthru; };