From 3c4cf6301aefd74bfd79510b8e5c141af4f975c4 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Mon, 16 Mar 2026 10:27:26 +0100 Subject: [PATCH] stdenvAdapters: add `overrideMkDerivationArgs` In addition to the use-case mentioned inside the function's documentation comment, I am motivated to add this function for two reasons: - My actual use-case is adding a guaranteed phase to every `stdenv.mkDerivation` via a nixpkgs overlay. Exposing this generic function allows me to do that, without having to replicate `defaultMkDerivationFromStdenv`. This relieves that maintainence burden for that overlay implementation, since that function has to be kept in sync with `stdenv/generic`. - I see value in adding this generic function over a specialized function. At first, I had a different implementation in mind, and tried to make due with the specialized functions that were already exposed. Having access to this generic function allowed me to experiment, and settle on a better implementation. This commit is based off of @SomeoneSerge's PR [1]. [1] https://github.com/NixOS/nixpkgs/pull/350350 Co-authored-by: SomeoneSerge --- pkgs/stdenv/adapters.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index d2efb4be73ef..9c3546237de6 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -215,6 +215,23 @@ rec { mkDerivationFromStdenv = extendMkDerivationArgs old (_: extraAttrs); }); + /* + Modify a stdenv so as to extend `mkDerivation`'s arguments. + A stronger version of `addAttrsToDerivation`. + + Example: + requireCcache = + overrideMkDerivationArgs + (oldAttrs: { + requiredSystemFeatures = oldAttrs.requiredSystemFeatures or [ ] ++ [ "ccache" ]; + }); + */ + overrideMkDerivationArgs = + extension: stdenv: + stdenv.override (old: { + mkDerivationFromStdenv = extendMkDerivationArgs old extension; + }); + /* Use the trace output to report all processed derivations with their license name.