about summary refs log tree commit diff
path: root/pkgs/development
diff options
context:
space:
mode:
authortalyz <kim.lindberger@gmail.com>2020-03-24 19:57:49 +0100
committerElis Hirwing <elis@hirwing.se>2020-04-03 10:11:15 +0200
commit8924a7de3d27f14f18ac9877d1d5e29ba474e566 (patch)
treed1d3ba21bbb2712a683754aa7a1dec0852916149 /pkgs/development
parent6c810c235d8d122f3d9e036073144a104120f930 (diff)
downloadnixlib-8924a7de3d27f14f18ac9877d1d5e29ba474e566.tar
nixlib-8924a7de3d27f14f18ac9877d1d5e29ba474e566.tar.gz
nixlib-8924a7de3d27f14f18ac9877d1d5e29ba474e566.tar.bz2
nixlib-8924a7de3d27f14f18ac9877d1d5e29ba474e566.tar.lz
nixlib-8924a7de3d27f14f18ac9877d1d5e29ba474e566.tar.xz
nixlib-8924a7de3d27f14f18ac9877d1d5e29ba474e566.tar.zst
nixlib-8924a7de3d27f14f18ac9877d1d5e29ba474e566.zip
php: Make buildEnv recursive + take extension deps into account
A slight rewrite of buildEnv which:

1. Makes buildEnv recursively add itself to its output, so that it can
   be accessed from any php derivation.

2. Orders the extension text strings according to their internalDeps
   attribute - dependencies have to be put before dependants in the
   php.ini or they will fail to load due to missing symbols.
Diffstat (limited to 'pkgs/development')
-rw-r--r--pkgs/development/interpreters/php/default.nix74
1 files changed, 51 insertions, 23 deletions
diff --git a/pkgs/development/interpreters/php/default.nix b/pkgs/development/interpreters/php/default.nix
index f23ebd67eaad..36f1d9f92e96 100644
--- a/pkgs/development/interpreters/php/default.nix
+++ b/pkgs/development/interpreters/php/default.nix
@@ -144,29 +144,57 @@ let
     };
   };
 
-  generic' = { version, sha256, ... }@args: let php = generic args; in php.overrideAttrs (_: {
-    passthru.buildEnv = { exts ? (_: []), extraConfig ? "" }: let
-      extraInit = writeText "custom-php.ini" ''
-        ${extraConfig}
-        ${lib.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}"
-      '';
-    };
-  });
+  generic' = { version, sha256, ... }@args:
+    let
+      php = generic args;
+      buildEnv = { exts ? (_: []), extraConfig ? "" }:
+        let
+          getExtName = ext: lib.removePrefix "php-" (builtins.parseDrvName ext.name).name;
+          extList = exts (callPackage ../../../top-level/php-packages.nix { inherit php; });
+
+          # Generate extension load configuration snippets from
+          # exts. 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) ext.internalDeps;
+                  })
+                extList);
+
+          extNames = map getExtName extList;
+          extraInit = writeText "custom-php.ini" ''
+            ${extraConfig}
+            ${lib.concatStringsSep "\n"
+              (lib.textClosureList extensionTexts extNames)}
+          '';
+        in
+          symlinkJoin {
+            name = "php-with-extensions-${version}";
+            inherit version;
+            nativeBuildInputs = [ makeWrapper ];
+            passthru.buildEnv = buildEnv;
+            paths = [ php ];
+            postBuild = ''
+              wrapProgram $out/bin/php \
+                --add-flags "-c ${extraInit}"
+              wrapProgram $out/bin/php-fpm \
+                --add-flags "-c ${extraInit}"
+            '';
+          };
+    in
+      php.overrideAttrs (_: {
+        passthru.buildEnv = buildEnv;
+      });
 
   php72base = generic' {
     version = "7.2.28";