48 lib.makeScope pkgs.newScope (self: let
49 inherit (self) buildPecl callPackage mkExtension php;
51 builders = import ../build-support/php/builders {
52 inherit callPackages callPackage buildPecl;
55 buildPecl = callPackage ../build-support/php/build-pecl.nix {
59 inherit (builders.v1) buildComposerProject buildComposerWithPlugin composerHooks mkComposerRepository;
61 # Next version of the builder
62 buildComposerProject2 = builders.v2.buildComposerProject;
63 composerHooks2 = builders.v2.composerHooks;
64 mkComposerVendor = builders.v2.mkComposerVendor;
66 # Wrap mkDerivation to prepend pname with "php-" to make names consistent
67 # with how buildPecl does it and make the file easier to overview.
68 mkDerivation = origArgs:
70 args = lib.fix (lib.extends
72 pname = "php-${previousAttrs.pname}";
73 passthru = (previousAttrs.passthru or { }) // {
74 updateScript = nix-update-script { };
76 meta = (previousAttrs.meta or { }) // {
77 mainProgram = previousAttrs.meta.mainProgram or previousAttrs.pname;
80 (if lib.isFunction origArgs then origArgs else (_: origArgs))
83 pkgs.stdenv.mkDerivation args;
85 # Function to build an extension which is shipped as part of the php
86 # source, based on the php version.
88 # Name passed is the name of the extension and is automatically used
89 # to add the configureFlag "--enable-${name}", which can be overridden.
91 # Build inputs is used for extra deps that may be needed. And zendExtension
92 # will mark the extension as a zend extension or not.
93 mkExtension = lib.makeOverridable
95 , configureFlags ? [ "--enable-${extName}" ]
99 , zendExtension ? false
103 }@args: stdenv.mkDerivation ((builtins.removeAttrs args [ "name" ]) // {
104 pname = "php-${name}";
105 extensionName = extName;
107 outputs = [ "out" "dev" ];
109 inherit (php.unwrapped) version src;
111 enableParallelBuilding = true;
113 nativeBuildInputs = [
121 inherit configureFlags internalDeps buildInputs zendExtension doCheck;
123 preConfigurePhases = [
125 "cdToExtensionRootPhase"
129 if [ -f "scripts/dev/genfiles" ]; then
130 ./scripts/dev/genfiles
134 cdToExtensionRootPhase = ''
135 # Go to extension source root.
140 nullglobRestore=$(shopt -p nullglob)
141 shopt -u nullglob # To make ?-globbing work
143 # Some extensions have a config0.m4 or config9.m4
144 if [ -f config?.m4 ]; then
145 mv config?.m4 config.m4
153 ${lib.concatMapStringsSep
155 (dep: "mkdir -p ext; ln -s ${dep.dev}/include ext/${dep.extensionName}")
163 NO_INTERACTION=yes SKIP_PERF_SENSITIVE=yes SKIP_ONLINE_TESTS=yes make test
170 mkdir -p $out/lib/php/extensions
171 cp modules/${extName}.so $out/lib/php/extensions/${extName}.so
172 mkdir -p $dev/include
173 ${rsync}/bin/rsync -r --filter="+ */" \
183 description = "PHP upstream extension: ${name}";
184 inherit (php.meta) maintainers homepage license;
190 # This is a set of interactive tools based on PHP.
192 box = callPackage ../development/php-packages/box { };
194 castor = callPackage ../development/php-packages/castor { };
196 composer = callPackage ../development/php-packages/composer { };
198 composer-local-repo-plugin = callPackage ../development/php-packages/composer-local-repo-plugin { };
200 cyclonedx-php-composer = callPackage ../development/php-packages/cyclonedx-php-composer { };
202 deployer = callPackage ../development/php-packages/deployer { };
204 grumphp = callPackage ../development/php-packages/grumphp { };
206 phan = callPackage ../development/php-packages/phan { };
208 phing = callPackage ../development/php-packages/phing { };
210 phive = callPackage ../development/php-packages/phive { };
212 php-codesniffer = callPackage ../development/php-packages/php-codesniffer { };
214 php-cs-fixer = callPackage ../development/php-packages/php-cs-fixer { };
216 php-parallel-lint = callPackage ../development/php-packages/php-parallel-lint { };
218 phpinsights = callPackage ../development/php-packages/phpinsights { };
220 phpmd = callPackage ../development/php-packages/phpmd { };
222 phpspy = callPackage ../development/php-packages/phpspy { };
224 phpstan = callPackage ../development/php-packages/phpstan { };
226 psalm = callPackage ../development/php-packages/psalm { };
228 psysh = callPackage ../development/php-packages/psysh { };
229 } // lib.optionalAttrs config.allowAliases {
230 phpcbf = throw "`phpcbf` is now deprecated, use `php-codesniffer` instead which contains both `phpcs` and `phpcbf`.";
231 phpcs = throw "`phpcs` is now deprecated, use `php-codesniffer` instead which contains both `phpcs` and `phpcbf`.";
234 # This is a set of PHP extensions meant to be used in php.buildEnv
235 # or php.withExtensions to extend the functionality of the PHP
237 # The extensions attributes is composed of three sections:
238 # 1. The contrib conditional extensions, which are only available on specific PHP versions
239 # 2. The contrib extensions available
240 # 3. The core extensions
244 amqp = callPackage ../development/php-packages/amqp { };
246 apcu = callPackage ../development/php-packages/apcu { };
248 ast = callPackage ../development/php-packages/ast { };
250 blackfire = callPackage ../development/tools/misc/blackfire/php-probe.nix { };
252 couchbase = callPackage ../development/php-packages/couchbase { };
254 datadog_trace = callPackage ../development/php-packages/datadog_trace {
255 buildPecl = buildPecl.override {
256 stdenv = if stdenv.hostPlatform.isDarwin then overrideSDK stdenv "11.0" else stdenv;
258 inherit (pkgs) darwin;
261 ds = callPackage ../development/php-packages/ds { };
263 event = callPackage ../development/php-packages/event { };
265 gnupg = callPackage ../development/php-packages/gnupg { };
267 grpc = callPackage ../development/php-packages/grpc { };
269 igbinary = callPackage ../development/php-packages/igbinary { };
271 imagick = callPackage ../development/php-packages/imagick { };
273 # Shadowed by built-in version on PHP < 8.3.
274 imap = callPackage ../development/php-packages/imap { };
276 inotify = callPackage ../development/php-packages/inotify { };
278 ioncube-loader = callPackage ../development/php-packages/ioncube-loader { };
280 mailparse = callPackage ../development/php-packages/mailparse { };
282 maxminddb = callPackage ../development/php-packages/maxminddb { };
284 memcache = callPackage ../development/php-packages/memcache { };
286 memcached = callPackage ../development/php-packages/memcached { };
288 meminfo = callPackage ../development/php-packages/meminfo { };
290 memprof = callPackage ../development/php-packages/memprof { };
292 mongodb = callPackage ../development/php-packages/mongodb {
293 inherit (pkgs) darwin;
296 msgpack = callPackage ../development/php-packages/msgpack { };
298 oci8 = callPackage ../development/php-packages/oci8 { };
300 opentelemetry = callPackage ../development/php-packages/opentelemetry { };
302 openswoole = callPackage ../development/php-packages/openswoole { };
304 pdlib = callPackage ../development/php-packages/pdlib { };
306 pcov = callPackage ../development/php-packages/pcov { };
308 pdo_oci = buildPecl rec {
309 inherit (php.unwrapped) src version;
312 sourceRoot = "php-${version}/ext/pdo_oci";
314 buildInputs = [ pkgs.oracle-instantclient ];
315 configureFlags = [ "--with-pdo-oci=instantclient,${pkgs.oracle-instantclient.lib}/lib" ];
317 internalDeps = [ php.extensions.pdo ];
320 sed -i -e 's|OCISDKMANINC=`.*$|OCISDKMANINC="${pkgs.oracle-instantclient.dev}/include"|' config.m4
323 meta.maintainers = lib.teams.php.members;
326 pdo_sqlsrv = callPackage ../development/php-packages/pdo_sqlsrv { };
328 phalcon = callPackage ../development/php-packages/phalcon { };
330 pinba = callPackage ../development/php-packages/pinba { };
332 protobuf = callPackage ../development/php-packages/protobuf { };
334 pspell = callPackage ../development/php-packages/pspell { };
336 rdkafka = callPackage ../development/php-packages/rdkafka { };
338 redis = callPackage ../development/php-packages/redis { };
340 relay = callPackage ../development/php-packages/relay { };
342 rrd = callPackage ../development/php-packages/rrd { };
344 smbclient = callPackage ../development/php-packages/smbclient { };
346 snuffleupagus = callPackage ../development/php-packages/snuffleupagus {
347 inherit (pkgs) darwin;
350 spx = callPackage ../development/php-packages/spx { };
352 sqlsrv = callPackage ../development/php-packages/sqlsrv { };
354 ssh2 = callPackage ../development/php-packages/ssh2 { };
356 swoole = callPackage ../development/php-packages/swoole { };
358 uv = callPackage ../development/php-packages/uv { };
360 vld = callPackage ../development/php-packages/vld { };
362 xdebug = callPackage ../development/php-packages/xdebug { };
364 yaml = callPackage ../development/php-packages/yaml { };
366 zstd = callPackage ../development/php-packages/zstd { };
367 } // lib.optionalAttrs config.allowAliases {
368 php-spx = throw "php-spx is deprecated, use spx instead";
372 # This list contains build instructions for different modules that one may
375 # These will be passed as arguments to mkExtension above.
378 { name = "bz2"; buildInputs = [ bzip2 ]; configureFlags = [ "--with-bz2=${bzip2.dev}" ]; }
379 { name = "calendar"; }
383 buildInputs = [ curl ];
384 configureFlags = [ "--with-curl=${curl.dev}" ];
390 buildInputs = [ libxml2 ];
394 # Add a PHP lower version bound constraint to avoid applying the patch on older PHP versions.
395 patches = lib.optionals (lib.versions.majorMinor php.version == "8.1") [
396 # Fix tests with libxml 2.12
397 # Part of 8.3.1RC1+, 8.2.14RC1+
399 url = "https://github.com/php/php-src/commit/061058a9b1bbd90d27d97d79aebcf2b5029767b0.patch";
400 hash = "sha256-0hOlAG+pOYp/gUU0MUMZvzWpgr0ncJi5GB8IeNxxyEU=";
405 ] ++ lib.optionals (lib.versions.majorMinor php.version == "8.1") [
406 # Backport of PHP_LIBXML_IGNORE_DEPRECATIONS_START and PHP_LIBXML_IGNORE_DEPRECATIONS_END
407 ../development/interpreters/php/php81-fix-libxml2-2.13-compatibility.patch
408 # Fix build with libxml2 2.13+. Has to be applied after libxml2 2.12 patch.
410 url = "https://github.com/php/php-src/commit/9b4f6b09d58a4e54ee60443bf9a8b166852c03e0.patch";
411 hash = "sha256-YC3I0BQi3o3+VmRu/UqpqPpaSC+ekPqzbORTHftbPvY=";
417 buildInputs = [ enchant2 ];
418 configureFlags = [ "--with-enchant" ];
421 { name = "exif"; doCheck = false; }
422 { name = "ffi"; buildInputs = [ libffi ]; }
425 buildInputs = [ pcre2 ];
427 { name = "filter"; buildInputs = [ pcre2 ]; }
428 { name = "ftp"; buildInputs = [ openssl ]; }
431 buildInputs = [ zlib gd ];
434 "--with-external-gd=${gd.dev}"
435 "--enable-gd-jis-conv"
441 buildInputs = [ gettext ];
442 postPhpize = ''substituteInPlace configure --replace-fail 'as_fn_error $? "Cannot locate header file libintl.h" "$LINENO" 5' ':' '';
443 configureFlags = [ "--with-gettext=${gettext}" ];
447 buildInputs = [ gmp ];
448 configureFlags = [ "--with-gmp=${gmp.dev}" ];
452 buildInputs = [ libiconv ];
453 configureFlags = [ "--with-iconv" ];
454 doCheck = stdenv.hostPlatform.isLinux;
458 buildInputs = [ uwimap openssl pam pcre2 libkrb5 ];
459 configureFlags = [ "--with-imap=${uwimap}" "--with-imap-ssl" "--with-kerberos" ];
460 # Using version from PECL on new PHP versions.
461 enable = lib.versionOlder php.version "8.3";
465 buildInputs = [ icu73 ];
469 buildInputs = [ openldap cyrus_sasl ];
472 "LDAP_DIR=${openldap.dev}"
473 "LDAP_INCDIR=${openldap.dev}/include"
474 "LDAP_LIBDIR=${openldap.out}/lib"
475 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
476 "--with-ldap-sasl=${cyrus_sasl.dev}"
482 buildInputs = [ oniguruma pcre2 ];
487 internalDeps = [ php.extensions.mysqlnd ];
488 configureFlags = [ "--with-mysqli=mysqlnd" "--with-mysql-sock=/run/mysqld/mysqld.sock" ];
493 buildInputs = [ zlib openssl ];
494 # The configure script doesn't correctly add library link
495 # flags, so we add them to the variable used by the Makefile
497 MYSQLND_SHARED_LIBADD = "-lz -lssl -lcrypto";
498 # The configure script builds a config.h which is never
499 # included. Let's include it in the main header file
500 # included by all .c-files.
502 (pkgs.writeText "mysqlnd_config.patch" ''
503 --- a/ext/mysqlnd/mysqlnd.h
504 +++ b/ext/mysqlnd/mysqlnd.h
506 +#ifdef HAVE_CONFIG_H
510 +----------------------------------------------------------------------+
511 | Copyright (c) The PHP Group |
517 buildInputs = [ pcre2 ] ++
519 (!stdenv.hostPlatform.isDarwin && lib.meta.availableOn stdenv.hostPlatform valgrind)
521 configureFlags = lib.optional php.ztsSupport "--disable-opcache-jit";
522 zendExtension = true;
523 postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
524 # Tests are flaky on darwin
525 rm ext/opcache/tests/blacklist.phpt
526 rm ext/opcache/tests/bug66338.phpt
527 rm ext/opcache/tests/bug78106.phpt
528 rm ext/opcache/tests/issue0115.phpt
529 rm ext/opcache/tests/issue0149.phpt
530 rm ext/opcache/tests/revalidate_path_01.phpt
532 # Tests launch the builtin webserver.
533 __darwinAllowLocalNetworking = true;
537 buildInputs = [ openssl ];
538 configureFlags = [ "--with-openssl" ];
541 # This provides a legacy OpenSSL PHP extension
542 # For situations where OpenSSL 3 do not support a set of features
543 # without a specific openssl.cnf file
545 name = "openssl-legacy";
547 buildInputs = [ openssl_1_1 ];
548 configureFlags = [ "--with-openssl" ];
552 { name = "pdo"; doCheck = false; }
555 internalDeps = [ php.extensions.pdo ];
556 configureFlags = [ "--with-pdo-dblib=${freetds}" ];
557 # Doesn't seem to work on darwin.
558 enable = (!stdenv.hostPlatform.isDarwin);
563 internalDeps = with php.extensions; [ pdo mysqlnd ];
564 configureFlags = [ "--with-pdo-mysql=mysqlnd" "PHP_MYSQL_SOCK=/run/mysqld/mysqld.sock" ];
569 internalDeps = [ php.extensions.pdo ];
570 buildInputs = [ unixODBC ];
571 configureFlags = [ "--with-pdo-odbc=unixODBC,${unixODBC}" ];
576 internalDeps = [ php.extensions.pdo ];
577 configureFlags = [ "--with-pdo-pgsql=${lib.getDev postgresql}" ];
582 internalDeps = [ php.extensions.pdo ];
583 buildInputs = [ sqlite ];
584 configureFlags = [ "--with-pdo-sqlite=${sqlite.dev}" ];
589 buildInputs = [ pcre2 ];
590 configureFlags = [ "--with-pgsql=${lib.getDev postgresql}" ];
593 { name = "posix"; doCheck = false; }
600 "--with-readline=${readline.dev}"
603 # Fix `--with-readline` option not being available.
604 # `PHP_ALWAYS_SHARED` generated by phpize enables all options
605 # without the possibility to override them. But when `--with-libedit`
606 # is enabled, `--with-readline` is not registered.
608 AC_DEFUN([PHP_ALWAYS_SHARED],[
609 test "[$]$1" != "no" && ext_shared=yes
611 ' | cat - ext/readline/config.m4 > ext/readline/config.m4.tmp
612 mv ext/readline/config.m4{.tmp,}
622 buildInputs = [ libxml2 pcre2 ];
626 patches = lib.optionals (lib.versions.majorMinor php.version == "8.1") [
627 # Fix tests with libxml2 2.12
629 url = "https://github.com/php/php-src/commit/061058a9b1bbd90d27d97d79aebcf2b5029767b0.patch";
630 hash = "sha256-0hOlAG+pOYp/gUU0MUMZvzWpgr0ncJi5GB8IeNxxyEU=";
635 # Backport of PHP_LIBXML_IGNORE_DEPRECATIONS_START and PHP_LIBXML_IGNORE_DEPRECATIONS_END
636 # Required for libxml2 2.13 compatibility patch.
637 ../development/interpreters/php/php81-fix-libxml2-2.13-compatibility.patch
638 # Fix build with libxml2 2.13+. Has to be applied after libxml2 2.12 patch.
640 url = "https://github.com/php/php-src/commit/9b4f6b09d58a4e54ee60443bf9a8b166852c03e0.patch";
641 hash = "sha256-YC3I0BQi3o3+VmRu/UqpqPpaSC+ekPqzbORTHftbPvY=";
647 buildInputs = [ net-snmp openssl ];
648 configureFlags = [ "--with-snmp" ];
649 # net-snmp doesn't build on darwin.
650 enable = (!stdenv.hostPlatform.isDarwin);
655 buildInputs = [ libxml2 ];
659 # Some tests are causing issues in the Darwin sandbox with issues
661 # Unknown: php_network_getaddresses: getaddrinfo for localhost failed: nodename nor servname provided
662 doCheck = !stdenv.hostPlatform.isDarwin;
663 internalDeps = [ php.extensions.session ];
664 patches = lib.optionals (lib.versions.majorMinor php.version == "8.1") [
665 # Fix tests with libxml2 2.12
667 url = "https://github.com/php/php-src/commit/061058a9b1bbd90d27d97d79aebcf2b5029767b0.patch";
668 hash = "sha256-0hOlAG+pOYp/gUU0MUMZvzWpgr0ncJi5GB8IeNxxyEU=";
673 # Backport of PHP_LIBXML_IGNORE_DEPRECATIONS_START and PHP_LIBXML_IGNORE_DEPRECATIONS_END
674 # Required for libxml2 2.13 compatibility patch.
675 ../development/interpreters/php/php81-fix-libxml2-2.13-compatibility.patch
676 # Fix build with libxml2 2.13+. Has to be applied after libxml2 2.12 patch.
678 url = "https://github.com/php/php-src/commit/9b4f6b09d58a4e54ee60443bf9a8b166852c03e0.patch";
679 hash = "sha256-YC3I0BQi3o3+VmRu/UqpqPpaSC+ekPqzbORTHftbPvY=";
687 { name = "sodium"; buildInputs = [ libsodium ]; }
690 buildInputs = [ sqlite ];
692 # The `sqlite3_bind_bug68849.phpt` test is currently broken for i686 Linux systems since sqlite 3.43, cf.:
693 # - https://github.com/php/php-src/issues/12076
694 # - https://www.sqlite.org/forum/forumpost/abbb95376ec6cd5f
695 patches = lib.optionals (stdenv.hostPlatform.isi686 && stdenv.hostPlatform.isLinux) [
696 ../development/interpreters/php/skip-sqlite3_bind_bug68849.phpt.patch
699 { name = "sysvmsg"; }
700 { name = "sysvsem"; }
701 { name = "sysvshm"; }
702 { name = "tidy"; configureFlags = [ "--with-tidy=${html-tidy}" ]; doCheck = false; }
705 patches = [ ../development/interpreters/php/fix-tokenizer-php81.patch ];
709 buildInputs = [ libxml2 ];
714 patches = lib.optionals (lib.versions.majorMinor php.version == "8.1") [
715 # Fix tests with libxml2 2.12
717 url = "https://github.com/php/php-src/commit/061058a9b1bbd90d27d97d79aebcf2b5029767b0.patch";
718 hash = "sha256-0hOlAG+pOYp/gUU0MUMZvzWpgr0ncJi5GB8IeNxxyEU=";
723 # Backport of PHP_LIBXML_IGNORE_DEPRECATIONS_START and PHP_LIBXML_IGNORE_DEPRECATIONS_END
724 # Required for libxml2 2.13 compatibility patch.
725 ../development/interpreters/php/php81-fix-libxml2-2.13-compatibility.patch
726 # Fix build with libxml2 2.13+. Has to be applied after libxml2 2.12 patch.
728 url = "https://github.com/php/php-src/commit/9b4f6b09d58a4e54ee60443bf9a8b166852c03e0.patch";
729 hash = "sha256-YC3I0BQi3o3+VmRu/UqpqPpaSC+ekPqzbORTHftbPvY=";
735 buildInputs = [ libxml2 ];
736 internalDeps = [ php.extensions.dom ];
737 env.NIX_CFLAGS_COMPILE = toString [ "-I../.." "-DHAVE_DOM" ];
745 buildInputs = [ libxml2 ];
749 patches = lib.optionals (lib.versions.majorMinor php.version == "8.1") [
750 # Fix tests with libxml2 2.12
752 url = "https://github.com/php/php-src/commit/061058a9b1bbd90d27d97d79aebcf2b5029767b0.patch";
753 hash = "sha256-0hOlAG+pOYp/gUU0MUMZvzWpgr0ncJi5GB8IeNxxyEU=";
758 # Backport of PHP_LIBXML_IGNORE_DEPRECATIONS_START and PHP_LIBXML_IGNORE_DEPRECATIONS_END
759 # Required for libxml2 2.13 compatibility patch.
760 ../development/interpreters/php/php81-fix-libxml2-2.13-compatibility.patch
761 # Fix build with libxml2 2.13+. Has to be applied after libxml2 2.12 patch.
763 url = "https://github.com/php/php-src/commit/9b4f6b09d58a4e54ee60443bf9a8b166852c03e0.patch";
764 hash = "sha256-YC3I0BQi3o3+VmRu/UqpqPpaSC+ekPqzbORTHftbPvY=";
770 buildInputs = [ libxslt libxml2 ];
771 internalDeps = [ php.extensions.dom ];
773 env.NIX_CFLAGS_COMPILE = toString [ "-I../.." "-DHAVE_DOM" ];
774 configureFlags = [ "--with-xsl=${libxslt.dev}" ];
778 internalDeps = [ php.extensions.dom ];
779 env.NIX_CFLAGS_COMPILE = "-I${libxml2.dev}/include/libxml2";
783 buildInputs = [ libzip pcre2 ];
791 buildInputs = [ zlib ];
798 # Convert the list of attrs:
799 # [ { name = <name>; ... } ... ]
801 # [ { name = <name>; value = <extension drv>; } ... ]
803 # which we later use listToAttrs to make all attrs available by name.
805 # Also filter out extensions based on the enable property.
806 namedExtensions = builtins.map
809 value = mkExtension (builtins.removeAttrs drv [ "enable" ]);
811 (builtins.filter (i: i.enable or true) extensionData);
813 # Produce the final attribute set of all extensions defined.
815 builtins.listToAttrs namedExtensions