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.
This commit is contained in:
talyz 2020-03-24 19:57:49 +01:00 committed by Elis Hirwing
parent 6c810c235d
commit 8924a7de3d
No known key found for this signature in database
GPG Key ID: D57EFA625C9A925F
2 changed files with 53 additions and 25 deletions

View File

@ -144,20 +144,45 @@ let
};
};
generic' = { version, sha256, ... }@args: let php = generic args; in php.overrideAttrs (_: {
passthru.buildEnv = { exts ? (_: []), extraConfig ? "" }: let
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.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; }))}
${lib.concatStringsSep "\n"
(lib.textClosureList extensionTexts extNames)}
'';
in symlinkJoin {
name = "php-custom-${version}";
in
symlinkJoin {
name = "php-with-extensions-${version}";
inherit version;
nativeBuildInputs = [ makeWrapper ];
passthru.buildEnv = buildEnv;
paths = [ php ];
postBuild = ''
wrapProgram $out/bin/php \
@ -166,6 +191,9 @@ let
--add-flags "-c ${extraInit}"
'';
};
in
php.overrideAttrs (_: {
passthru.buildEnv = buildEnv;
});
php72base = generic' {

View File

@ -717,7 +717,7 @@ let
, doCheck ? true
, ...
}: stdenv.mkDerivation {
pname = "php-ext-${name}";
pname = "php-${name}";
inherit (php) version src;
sourceRoot = "php-${php.version}/ext/${name}";
@ -746,7 +746,7 @@ let
checkPhase = "echo n | make test";
installPhase = ''
mkdir -p $out/lib/php/extensions
cp modules/${name}.so $out/lib/php/extensions/ext-${name}.so
cp modules/${name}.so $out/lib/php/extensions/${name}.so
'';
};