From f696ae3c9141b8347383818bb40acafa2cf86ae4 Mon Sep 17 00:00:00 2001 From: Piotr Kwiecinski <2151333+piotrkwiecinski@users.noreply.github.com> Date: Sun, 19 Apr 2026 12:05:12 +0200 Subject: [PATCH] php: fix infinite recursion with overrideAttrs --- pkgs/development/interpreters/php/generic.nix | 10 +++++++-- pkgs/test/php/default.nix | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pkgs/development/interpreters/php/generic.nix b/pkgs/development/interpreters/php/generic.nix index b40972d7696f..c69bf85633b8 100644 --- a/pkgs/development/interpreters/php/generic.nix +++ b/pkgs/development/interpreters/php/generic.nix @@ -399,9 +399,15 @@ let newPhpAttrsOverrides = lib.composeExtensions (lib.toExtension phpAttrsOverrides) ( lib.toExtension f ); - php = generic (args // { phpAttrsOverrides = newPhpAttrsOverrides; }); + phpOverridden = finalAttrs.overrideAttrs f; in - php; + phpOverridden + // { + passthru = phpOverridden.passthru // { + buildEnv = mkBuildEnv { phpAttrsOverrides = newPhpAttrsOverrides; } [ ]; + withExtensions = mkWithExtensions { phpAttrsOverrides = newPhpAttrsOverrides; } [ ]; + }; + }; inherit ztsSupport; services.default = { diff --git a/pkgs/test/php/default.nix b/pkgs/test/php/default.nix index f2f129925f04..c203bc026fce 100644 --- a/pkgs/test/php/default.nix +++ b/pkgs/test/php/default.nix @@ -2,6 +2,8 @@ lib, php, runCommand, + stdenv, + stdenvAdapters, }: let @@ -96,6 +98,26 @@ in ${check (builtins.match ".*oAs-second.*" customPhp.postInstall != null)} ''; + # Regression test for https://github.com/NixOS/nixpkgs/issues/509863: + # wrapping php's stdenv with an adapter that uses `extendMkDerivationArgs` + # (e.g. `keepDebugInfo`) used to trigger an infinite recursion via the + # custom `passthru.overrideAttrs` defined for unwrapped php. Forcing the + # derivation here would stack-overflow before the fix; checking + # `dontStrip` also confirms the adapter actually applied. + stdenvAdapter-keepDebugInfo-does-not-recurse = + let + customPhp = php.override { + stdenv = stdenvAdapters.keepDebugInfo stdenv; + }; + in + runTest "php-test-stdenvAdapter-keepDebugInfo-does-not-recurse" '' + checking "if the override evaluates without infinite recursion" + ${check (builtins.isString customPhp.unwrapped.drvPath)} + + checking "if keepDebugInfo's dontStrip propagated to the unwrapped derivation" + ${check (customPhp.unwrapped.dontStrip or false)} + ''; + wrapped-overrideAttrs-stacks = let customPhp = lib.pipe php [