php: fix infinite recursion with overrideAttrs

This commit is contained in:
Piotr Kwiecinski
2026-04-19 12:05:12 +02:00
parent 98f92e9c00
commit f696ae3c91
2 changed files with 30 additions and 2 deletions

View File

@@ -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 = {

View File

@@ -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 [