summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2020-02-06 20:05:34 +0100
committerMaximilian Bosch <maximilian@mbosch.me>2020-03-09 20:41:28 +0100
commit0bf5619fe0f269c483750a5a3feceefe62e7ffee (patch)
tree5f8d1205429097534d33f32eabf14fe1767ddf60
parent75aec2aae373445d7e2020cf8e0ffc3de9250270 (diff)
downloadnixpkgs-0bf5619fe0f269c483750a5a3feceefe62e7ffee.tar
nixpkgs-0bf5619fe0f269c483750a5a3feceefe62e7ffee.tar.gz
nixpkgs-0bf5619fe0f269c483750a5a3feceefe62e7ffee.tar.bz2
nixpkgs-0bf5619fe0f269c483750a5a3feceefe62e7ffee.tar.lz
nixpkgs-0bf5619fe0f269c483750a5a3feceefe62e7ffee.tar.xz
nixpkgs-0bf5619fe0f269c483750a5a3feceefe62e7ffee.tar.zst
nixpkgs-0bf5619fe0f269c483750a5a3feceefe62e7ffee.zip
php: add `buildEnv` function for additional config on the CLI SAPI
Initially discussed in #55460.

This patch adds a `buildEnv` function to `php` that has the
following features:

* `php.buildEnv { extraConfig = /* ... */; }` to specify custom
  `php.ini` args for the CLI.

* `php.buildEnv { exts = phpPackages: [phpPackages.apcu] }` to
  create a PHP interpreter for the CLI with the `apcu` extension.
-rw-r--r--pkgs/development/interpreters/php/default.nix35
-rw-r--r--pkgs/top-level/php-packages.nix2
2 files changed, 32 insertions, 5 deletions
diff --git a/pkgs/development/interpreters/php/default.nix b/pkgs/development/interpreters/php/default.nix
index a31bbe73cae..77d27dfd42a 100644
--- a/pkgs/development/interpreters/php/default.nix
+++ b/pkgs/development/interpreters/php/default.nix
@@ -6,7 +6,8 @@
 , libxslt, libmcrypt, bzip2, icu, openldap, cyrus_sasl, libmhash, unixODBC
 , uwimap, pam, gmp, apacheHttpd, libiconv, systemd, libsodium, html-tidy, libargon2
 , gd, freetype, libXpm, libjpeg, libpng, libwebp
-, libzip, valgrind, oniguruma
+, libzip, valgrind, oniguruma, symlinkJoin, writeText
+, makeWrapper, callPackage
 }:
 
 with lib;
@@ -255,7 +256,7 @@ let
         description = "An HTML-embedded scripting language";
         homepage = https://www.php.net/;
         license = licenses.php301;
-        maintainers = with maintainers; [ globin etu ];
+        maintainers = with maintainers; [ globin etu ma27 ];
         platforms = platforms.all;
         outputsToInstall = [ "out" "dev" ];
       };
@@ -268,8 +269,32 @@ let
 
     };
 
+    generic' = { version, sha256, ... }@args: let php = generic args; in php.overrideAttrs (_: {
+      passthru.buildEnv = { exts ? (_: []), extraConfig ? "" }: let
+        extraInit = writeText "custom-php.ini" ''
+          ${extraConfig}
+          ${concatMapStringsSep "\n" (ext: let
+            extName = lib.removePrefix "php-" (builtins.parseDrvName ext.name).name;
+            type = "${lib.optionalString (ext.zendExtension or false) "zend_"}extension";
+          in ''
+            ${type}=${ext}/lib/php/extensions/${extName}.so
+          '') (exts (callPackage ../../../top-level/php-packages.nix { inherit php; }))}
+        '';
+      in symlinkJoin {
+        name = "php-custom-${version}";
+        nativeBuildInputs = [ makeWrapper ];
+        paths = [ php ];
+        postBuild = ''
+          wrapProgram $out/bin/php \
+            --add-flags "-c ${extraInit}"
+          wrapProgram $out/bin/php-fpm \
+            --add-flags "-c ${extraInit}"
+        '';
+      };
+    });
+
 in {
-  php72 = generic {
+  php72 = generic' {
     version = "7.2.27";
     sha256 = "0jbhc8x2i6xx6p7zc30ahg9xplsqlz334m1w13mhr1qv2xdnkh2v";
 
@@ -277,7 +302,7 @@ in {
     extraPatches = optional stdenv.isDarwin ./php72-darwin-isfinite.patch;
   };
 
-  php73 = generic {
+  php73 = generic' {
     version = "7.3.14";
     sha256 = "0wn2qsfrnch90l8nxbpcjd2q0ijzdiiyhvcpbycngki9r6xwppxr";
 
@@ -285,7 +310,7 @@ in {
     extraPatches = optional stdenv.isDarwin ./php73-darwin-isfinite.patch;
   };
 
-  php74 = generic {
+  php74 = generic' {
     version = "7.4.3";
     sha256 = "wVF7pJV4+y3MZMc6Ptx21PxQfEp6xjmYFYTMfTtMbRQ=";
   };
diff --git a/pkgs/top-level/php-packages.nix b/pkgs/top-level/php-packages.nix
index 50bf1ae5dbf..5ef8e722620 100644
--- a/pkgs/top-level/php-packages.nix
+++ b/pkgs/top-level/php-packages.nix
@@ -664,6 +664,8 @@ let
 
     doCheck = true;
     checkTarget = "test";
+
+    zendExtension = true;
   };
 
   yaml = buildPecl {