49 lib.makeScope pkgs.newScope (self: with self; {
50 buildPecl = callPackage ../build-support/php/build-pecl.nix {
54 composerHooks = callPackages ../build-support/php/hooks { };
56 mkComposerRepository = callPackage ../build-support/php/build-composer-repository.nix { };
57 buildComposerProject = callPackage ../build-support/php/build-composer-project.nix { };
59 # Wrap mkDerivation to prepend pname with "php-" to make names consistent
60 # with how buildPecl does it and make the file easier to overview.
61 mkDerivation = origArgs:
63 args = lib.fix (lib.extends
65 pname = "php-${previousAttrs.pname}";
66 passthru = (previousAttrs.passthru or { }) // {
67 updateScript = nix-update-script { };
69 meta = (previousAttrs.meta or { }) // {
70 mainProgram = previousAttrs.meta.mainProgram or previousAttrs.pname;
73 (if lib.isFunction origArgs then origArgs else (_: origArgs))
76 pkgs.stdenv.mkDerivation args;
78 # Function to build an extension which is shipped as part of the php
79 # source, based on the php version.
81 # Name passed is the name of the extension and is automatically used
82 # to add the configureFlag "--enable-${name}", which can be overridden.
84 # Build inputs is used for extra deps that may be needed. And zendExtension
85 # will mark the extension as a zend extension or not.
86 mkExtension = lib.makeOverridable
88 , configureFlags ? [ "--enable-${extName}" ]
92 , zendExtension ? false
96 }@args: stdenv.mkDerivation ((builtins.removeAttrs args [ "name" ]) // {
97 pname = "php-${name}";
98 extensionName = extName;
100 outputs = [ "out" "dev" ];
102 inherit (php.unwrapped) version src;
104 enableParallelBuilding = true;
106 nativeBuildInputs = [
114 inherit configureFlags internalDeps buildInputs zendExtension doCheck;
116 preConfigurePhases = [
118 "cdToExtensionRootPhase"
122 if [ -f "scripts/dev/genfiles" ]; then
123 ./scripts/dev/genfiles
127 cdToExtensionRootPhase = ''
128 # Go to extension source root.
133 nullglobRestore=$(shopt -p nullglob)
134 shopt -u nullglob # To make ?-globbing work
136 # Some extensions have a config0.m4 or config9.m4
137 if [ -f config?.m4 ]; then
138 mv config?.m4 config.m4
146 ${lib.concatMapStringsSep
148 (dep: "mkdir -p ext; ln -s ${dep.dev}/include ext/${dep.extensionName}")
156 NO_INTERACTION=yes SKIP_PERF_SENSITIVE=yes make test
163 mkdir -p $out/lib/php/extensions
164 cp modules/${extName}.so $out/lib/php/extensions/${extName}.so
165 mkdir -p $dev/include
166 ${rsync}/bin/rsync -r --filter="+ */" \
176 description = "PHP upstream extension: ${name}";
177 inherit (php.meta) maintainers homepage license;
183 # This is a set of interactive tools based on PHP.
185 box = callPackage ../development/php-packages/box { };
187 castor = callPackage ../development/php-packages/castor { };
189 composer = callPackage ../development/php-packages/composer { };
191 deployer = callPackage ../development/php-packages/deployer { };
193 grumphp = callPackage ../development/php-packages/grumphp { };
195 phan = callPackage ../development/php-packages/phan { };
197 phing = callPackage ../development/php-packages/phing { };
199 phive = callPackage ../development/php-packages/phive { };
201 php-cs-fixer = callPackage ../development/php-packages/php-cs-fixer { };
203 php-parallel-lint = callPackage ../development/php-packages/php-parallel-lint { };
205 phpcbf = callPackage ../development/php-packages/phpcbf { };
207 phpcs = callPackage ../development/php-packages/phpcs { };
209 phpmd = callPackage ../development/php-packages/phpmd { };
211 phpstan = callPackage ../development/php-packages/phpstan { };
213 psalm = callPackage ../development/php-packages/psalm { };
215 psysh = callPackage ../development/php-packages/psysh { };
220 # This is a set of PHP extensions meant to be used in php.buildEnv
221 # or php.withExtensions to extend the functionality of the PHP
223 # The extensions attributes is composed of three sections:
224 # 1. The contrib conditional extensions, which are only available on specific PHP versions
225 # 2. The contrib extensions available
226 # 3. The core extensions
228 # Contrib conditional extensions
229 lib.optionalAttrs (!(lib.versionAtLeast php.version "8.3")) {
230 blackfire = callPackage ../development/tools/misc/blackfire/php-probe.nix { inherit php; };
234 amqp = callPackage ../development/php-packages/amqp { };
236 apcu = callPackage ../development/php-packages/apcu { };
238 ast = callPackage ../development/php-packages/ast { };
240 couchbase = callPackage ../development/php-packages/couchbase { };
242 datadog_trace = callPackage ../development/php-packages/datadog_trace {
243 buildPecl = buildPecl.override {
244 stdenv = if stdenv.isDarwin then overrideSDK stdenv "11.0" else stdenv;
246 inherit (pkgs) darwin;
249 ds = callPackage ../development/php-packages/ds { };
251 event = callPackage ../development/php-packages/event { };
253 gnupg = callPackage ../development/php-packages/gnupg { };
255 grpc = callPackage ../development/php-packages/grpc { };
257 igbinary = callPackage ../development/php-packages/igbinary { };
259 imagick = callPackage ../development/php-packages/imagick { };
261 inotify = callPackage ../development/php-packages/inotify { };
263 mailparse = callPackage ../development/php-packages/mailparse { };
265 maxminddb = callPackage ../development/php-packages/maxminddb { };
267 memcache = callPackage ../development/php-packages/memcache { };
269 memcached = callPackage ../development/php-packages/memcached { };
271 meminfo = callPackage ../development/php-packages/meminfo { };
273 memprof = callPackage ../development/php-packages/memprof { };
275 mongodb = callPackage ../development/php-packages/mongodb {
276 inherit (pkgs) darwin;
279 msgpack = callPackage ../development/php-packages/msgpack { };
281 oci8 = callPackage ../development/php-packages/oci8 { };
283 opentelemetry = callPackage ../development/php-packages/opentelemetry { };
285 openswoole = callPackage ../development/php-packages/openswoole { };
287 pdlib = callPackage ../development/php-packages/pdlib { };
289 pcov = callPackage ../development/php-packages/pcov { };
291 pdo_oci = buildPecl rec {
292 inherit (php.unwrapped) src version;
295 sourceRoot = "php-${version}/ext/pdo_oci";
297 buildInputs = [ pkgs.oracle-instantclient ];
298 configureFlags = [ "--with-pdo-oci=instantclient,${pkgs.oracle-instantclient.lib}/lib" ];
300 internalDeps = [ php.extensions.pdo ];
303 sed -i -e 's|OCISDKMANINC=`.*$|OCISDKMANINC="${pkgs.oracle-instantclient.dev}/include"|' config.m4
306 meta.maintainers = lib.teams.php.members;
309 pdo_sqlsrv = callPackage ../development/php-packages/pdo_sqlsrv { };
311 phalcon = callPackage ../development/php-packages/phalcon { };
313 php-spx = callPackage ../development/php-packages/php-spx { };
315 pinba = callPackage ../development/php-packages/pinba { };
317 protobuf = callPackage ../development/php-packages/protobuf { };
319 rdkafka = callPackage ../development/php-packages/rdkafka { };
321 redis = callPackage ../development/php-packages/redis { };
323 relay = callPackage ../development/php-packages/relay { inherit php; };
325 rrd = callPackage ../development/php-packages/rrd { };
327 smbclient = callPackage ../development/php-packages/smbclient { };
329 snuffleupagus = callPackage ../development/php-packages/snuffleupagus {
330 inherit (pkgs) darwin;
333 sqlsrv = callPackage ../development/php-packages/sqlsrv { };
335 ssh2 = callPackage ../development/php-packages/ssh2 { };
337 swoole = callPackage ../development/php-packages/swoole { };
339 uv = callPackage ../development/php-packages/uv { };
341 vld = callPackage ../development/php-packages/vld { };
343 xdebug = callPackage ../development/php-packages/xdebug { };
345 yaml = callPackage ../development/php-packages/yaml { };
349 # This list contains build instructions for different modules that one may
352 # These will be passed as arguments to mkExtension above.
355 { name = "bz2"; buildInputs = [ bzip2 ]; configureFlags = [ "--with-bz2=${bzip2.dev}" ]; }
356 { name = "calendar"; }
360 buildInputs = [ curl ];
361 configureFlags = [ "--with-curl=${curl.dev}" ];
367 buildInputs = [ libxml2 ];
374 buildInputs = [ enchant2 ];
375 configureFlags = [ "--with-enchant" ];
378 { name = "exif"; doCheck = false; }
379 { name = "ffi"; buildInputs = [ libffi ]; }
382 buildInputs = [ pcre2 ];
384 { name = "filter"; buildInputs = [ pcre2 ]; }
385 { name = "ftp"; buildInputs = [ openssl ]; }
388 buildInputs = [ zlib gd ];
391 "--with-external-gd=${gd.dev}"
392 "--enable-gd-jis-conv"
398 buildInputs = [ gettext ];
399 postPhpize = ''substituteInPlace configure --replace 'as_fn_error $? "Cannot locate header file libintl.h" "$LINENO" 5' ':' '';
400 configureFlags = [ "--with-gettext=${gettext}" ];
404 buildInputs = [ gmp ];
405 configureFlags = [ "--with-gmp=${gmp.dev}" ];
410 "--with-iconv${lib.optionalString stdenv.isDarwin "=${libiconv}"}"
416 buildInputs = [ uwimap openssl pam pcre2 libkrb5 ];
417 configureFlags = [ "--with-imap=${uwimap}" "--with-imap-ssl" "--with-kerberos" ];
421 buildInputs = [ icu64 ];
425 buildInputs = [ openldap cyrus_sasl ];
428 "LDAP_DIR=${openldap.dev}"
429 "LDAP_INCDIR=${openldap.dev}/include"
430 "LDAP_LIBDIR=${openldap.out}/lib"
431 ] ++ lib.optionals stdenv.isLinux [
432 "--with-ldap-sasl=${cyrus_sasl.dev}"
438 buildInputs = [ oniguruma pcre2 ];
443 internalDeps = [ php.extensions.mysqlnd ];
444 configureFlags = [ "--with-mysqli=mysqlnd" "--with-mysql-sock=/run/mysqld/mysqld.sock" ];
449 buildInputs = [ zlib openssl ];
450 # The configure script doesn't correctly add library link
451 # flags, so we add them to the variable used by the Makefile
453 MYSQLND_SHARED_LIBADD = "-lssl -lcrypto";
454 # The configure script builds a config.h which is never
455 # included. Let's include it in the main header file
456 # included by all .c-files.
458 (pkgs.writeText "mysqlnd_config.patch" ''
459 --- a/ext/mysqlnd/mysqlnd.h
460 +++ b/ext/mysqlnd/mysqlnd.h
462 +#ifdef HAVE_CONFIG_H
466 +----------------------------------------------------------------------+
467 | Copyright (c) The PHP Group |
473 buildInputs = [ pcre2 ] ++
475 (!stdenv.isDarwin && lib.meta.availableOn stdenv.hostPlatform valgrind)
477 zendExtension = true;
478 postPatch = lib.optionalString stdenv.isDarwin ''
479 # Tests are flaky on darwin
480 rm ext/opcache/tests/blacklist.phpt
481 rm ext/opcache/tests/bug66338.phpt
482 rm ext/opcache/tests/bug78106.phpt
483 rm ext/opcache/tests/issue0115.phpt
484 rm ext/opcache/tests/issue0149.phpt
485 rm ext/opcache/tests/revalidate_path_01.phpt
487 # Tests launch the builtin webserver.
488 __darwinAllowLocalNetworking = true;
492 buildInputs = [ openssl ];
493 configureFlags = [ "--with-openssl" ];
496 # This provides a legacy OpenSSL PHP extension
497 # For situations where OpenSSL 3 do not support a set of features
498 # without a specific openssl.cnf file
500 name = "openssl-legacy";
502 buildInputs = [ openssl_1_1 ];
503 configureFlags = [ "--with-openssl" ];
507 { name = "pdo"; doCheck = false; }
510 internalDeps = [ php.extensions.pdo ];
511 configureFlags = [ "--with-pdo-dblib=${freetds}" ];
512 # Doesn't seem to work on darwin.
513 enable = (!stdenv.isDarwin);
518 internalDeps = with php.extensions; [ pdo mysqlnd ];
519 configureFlags = [ "--with-pdo-mysql=mysqlnd" "PHP_MYSQL_SOCK=/run/mysqld/mysqld.sock" ];
524 internalDeps = [ php.extensions.pdo ];
525 configureFlags = [ "--with-pdo-odbc=unixODBC,${unixODBC}" ];
530 internalDeps = [ php.extensions.pdo ];
531 configureFlags = [ "--with-pdo-pgsql=${postgresql}" ];
536 internalDeps = [ php.extensions.pdo ];
537 buildInputs = [ sqlite ];
538 configureFlags = [ "--with-pdo-sqlite=${sqlite.dev}" ];
543 buildInputs = [ pcre2 ];
544 configureFlags = [ "--with-pgsql=${postgresql}" ];
547 { name = "posix"; doCheck = false; }
548 { name = "pspell"; configureFlags = [ "--with-pspell=${aspell}" ]; }
555 "--with-readline=${readline.dev}"
558 # Fix `--with-readline` option not being available.
559 # `PHP_ALWAYS_SHARED` generated by phpize enables all options
560 # without the possibility to override them. But when `--with-libedit`
561 # is enabled, `--with-readline` is not registered.
563 AC_DEFUN([PHP_ALWAYS_SHARED],[
564 test "[$]$1" != "no" && ext_shared=yes
566 ' | cat - ext/readline/config.m4 > ext/readline/config.m4.tmp
567 mv ext/readline/config.m4{.tmp,}
577 buildInputs = [ libxml2 pcre2 ];
584 buildInputs = [ net-snmp openssl ];
585 configureFlags = [ "--with-snmp" ];
586 # net-snmp doesn't build on darwin.
587 enable = (!stdenv.isDarwin);
592 buildInputs = [ libxml2 ];
602 { name = "sodium"; buildInputs = [ libsodium ]; }
605 buildInputs = [ sqlite ];
607 # The `sqlite3_bind_bug68849.phpt` test is currently broken for i686 Linux systems since sqlite 3.43, cf.:
608 # - https://github.com/php/php-src/issues/12076
609 # - https://www.sqlite.org/forum/forumpost/abbb95376ec6cd5f
610 patches = lib.optional (stdenv.isi686 && stdenv.isLinux) ../development/interpreters/php/skip-sqlite3_bind_bug68849.phpt.patch;
612 { name = "sysvmsg"; }
613 { name = "sysvsem"; }
614 { name = "sysvshm"; }
615 { name = "tidy"; configureFlags = [ "--with-tidy=${html-tidy}" ]; doCheck = false; }
618 patches = [ ../development/interpreters/php/fix-tokenizer-php81.patch ];
622 buildInputs = [ libxml2 ];
630 buildInputs = [ libxml2 ];
631 internalDeps = [ php.extensions.dom ];
632 env.NIX_CFLAGS_COMPILE = toString [ "-I../.." "-DHAVE_DOM" ];
640 buildInputs = [ libxml2 ];
647 buildInputs = [ libxslt libxml2 ];
649 configureFlags = [ "--with-xsl=${libxslt.dev}" ];
651 { name = "zend_test"; }
654 buildInputs = [ libzip pcre2 ];
662 buildInputs = [ zlib ];
669 # Convert the list of attrs:
670 # [ { name = <name>; ... } ... ]
672 # [ { name = <name>; value = <extension drv>; } ... ]
674 # which we later use listToAttrs to make all attrs available by name.
676 # Also filter out extensions based on the enable property.
677 namedExtensions = builtins.map
680 value = mkExtension drv;
682 (builtins.filter (i: i.enable or true) extensionData);
684 # Produce the final attribute set of all extensions defined.
686 builtins.listToAttrs namedExtensions