From a46326141570098adc676cd66dc8030fa36d4998 Mon Sep 17 00:00:00 2001 From: talyz Date: Sat, 11 Apr 2020 21:48:37 +0200 Subject: [PATCH] php.buildEnv: Make the exported php package overridable This implements the override pattern for builds done with buildEnv, so that we can, for example, write php.override { fpmSupport = false; } and get a PHP package with the default extensions enabled, but PHP compiled without fpm support. --- pkgs/development/interpreters/php/default.nix | 82 ++++++++++--------- pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/pkgs/development/interpreters/php/default.nix b/pkgs/development/interpreters/php/default.nix index 1d6576b383cd..4a80f79deebb 100644 --- a/pkgs/development/interpreters/php/default.nix +++ b/pkgs/development/interpreters/php/default.nix @@ -148,55 +148,61 @@ let generic' = { version, sha256, self, selfWithExtensions, ... }@args: let - php = generic (builtins.removeAttrs args [ "self" "selfWithExtensions" ]); + filteredArgs = builtins.removeAttrs args [ "self" "selfWithExtensions" ]; + php = generic filteredArgs; php-packages = (callPackage ../../../top-level/php-packages.nix { php = self; phpWithExtensions = selfWithExtensions; }); - buildEnv = { extensions ? (_: []), extraConfig ? "" }: - let - getExtName = ext: lib.removePrefix "php-" (builtins.parseDrvName ext.name).name; - enabledExtensions = extensions php-packages.extensions; + buildEnv = lib.makeOverridable ( + { extensions ? (_: []), extraConfig ? "", ... }@innerArgs: + let + filteredInnerArgs = builtins.removeAttrs innerArgs [ "extensions" "extraConfig" ]; + allArgs = filteredArgs // filteredInnerArgs; + php = generic allArgs; - # Generate extension load configuration snippets from the - # extension parameter. This is an attrset suitable for use - # with textClosureList, which is used to put the strings in - # the right order - if a plugin which is dependent on - # another plugin is placed before its dependency, it will - # fail to load. - extensionTexts = - lib.listToAttrs - (map (ext: - let - extName = getExtName ext; - type = "${lib.optionalString (ext.zendExtension or false) "zend_"}extension"; - in - lib.nameValuePair extName { - text = "${type}=${ext}/lib/php/extensions/${extName}.so"; - deps = lib.optionals (ext ? internalDeps) - (map getExtName ext.internalDeps); - }) - enabledExtensions); + getExtName = ext: lib.removePrefix "php-" (builtins.parseDrvName ext.name).name; + enabledExtensions = extensions php-packages.extensions; - extNames = map getExtName enabledExtensions; - extraInit = writeText "custom-php.ini" '' + # Generate extension load configuration snippets from the + # extension parameter. This is an attrset suitable for use + # with textClosureList, which is used to put the strings in + # the right order - if a plugin which is dependent on + # another plugin is placed before its dependency, it will + # fail to load. + extensionTexts = + lib.listToAttrs + (map (ext: + let + extName = getExtName ext; + type = "${lib.optionalString (ext.zendExtension or false) "zend_"}extension"; + in + lib.nameValuePair extName { + text = "${type}=${ext}/lib/php/extensions/${extName}.so"; + deps = lib.optionals (ext ? internalDeps) + (map getExtName ext.internalDeps); + }) + enabledExtensions); + + extNames = map getExtName enabledExtensions; + extraInit = writeText "custom-php.ini" '' ${lib.concatStringsSep "\n" (lib.textClosureList extensionTexts extNames)} ${extraConfig} ''; - in - symlinkJoin { - name = "php-with-extensions-${version}"; - inherit (php) version; - nativeBuildInputs = [ makeWrapper ]; - passthru = { - inherit buildEnv withExtensions enabledExtensions; - inherit (php-packages) packages extensions; - }; - paths = [ php ]; - postBuild = '' + in + symlinkJoin { + name = "php-with-extensions-${version}"; + inherit (php) version; + nativeBuildInputs = [ makeWrapper ]; + passthru = { + inherit buildEnv withExtensions enabledExtensions; + inherit (php-packages) packages extensions; + }; + paths = [ php ]; + postBuild = '' cp ${extraInit} $out/lib/custom-php.ini wrapProgram $out/bin/php --set PHP_INI_SCAN_DIR $out/lib @@ -205,7 +211,7 @@ let wrapProgram $out/bin/php-fpm --set PHP_INI_SCAN_DIR $out/lib fi ''; - }; + }); withExtensions = extensions: buildEnv { inherit extensions; }; in diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 78f07dc3c166..7f2c34039b46 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -9494,7 +9494,7 @@ in php73Extensions = recurseIntoAttrs php73.extensions; php74Extensions = recurseIntoAttrs php74.extensions; - inherit (callPackages ../development/interpreters/php { + inherit (callPackage ../development/interpreters/php { stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv; }) php74 php73 php72 php74base php73base php72base;