Merge pull request #85026 from talyz/php_buildenv_override

php.buildEnv: Make the exported php package overridable, improve handling of currently enabled extensions, etc

authored by

Elis Hirwing and committed by
GitHub
27b9b7b3 3407b8c0

+369 -326
+43 -32
doc/languages-frameworks/php.section.md
··· 9 9 Several versions of PHP are available on Nix, each of which having a 10 10 wide variety of extensions and libraries available. 11 11 12 - The attribute `php` refers to the version of PHP considered most 13 - stable and thoroughly tested in nixpkgs for any given release of 14 - NixOS. Note that while this version of PHP may not be the latest major 15 - release from upstream, any version of PHP supported in nixpkgs may be 16 - utilized by specifying the desired attribute by version, such as 17 - `php74`. 12 + The different versions of PHP that nixpkgs provides are located under 13 + attributes named based on major and minor version number; e.g., 14 + `php74` is PHP 7.4. 18 15 19 16 Only versions of PHP that are supported by upstream for the entirety 20 17 of a given NixOS release will be included in that release of 21 18 NixOS. See [PHP Supported 22 19 Versions](https://www.php.net/supported-versions.php). 23 20 21 + The attribute `php` refers to the version of PHP considered most 22 + stable and thoroughly tested in nixpkgs for any given release of 23 + NixOS - not necessarily the latest major release from upstream. 24 + 25 + All available PHP attributes are wrappers around their respective 26 + binary PHP package and provide commonly used extensions this way. The 27 + real PHP 7.4 package, i.e. the unwrapped one, is available as 28 + `php74.unwrapped`; see the next section for more details. 29 + 24 30 Interactive tools built on PHP are put in `php.packages`; composer is 25 31 for example available at `php.packages.composer`. 26 32 ··· 30 36 `php.extensions.opcache` and the third-party ImageMagick extension at 31 37 `php.extensions.imagick`. 32 38 33 - The different versions of PHP that nixpkgs provides is located under 34 - attributes named based on major and minor version number; e.g., 35 - `php74` is PHP 7.4 with commonly used extensions installed, 36 - `php74base` is the same PHP runtime without extensions. 37 - 38 - #### Installing PHP with packages 39 + #### Installing PHP with extensions 39 40 40 41 A PHP package with specific extensions enabled can be built using 41 42 `php.withExtensions`. This is a function which accepts an anonymous 42 - function as its only argument; the function should take one argument, 43 - the set of all extensions, and return a list of wanted extensions. For 44 - example, a PHP package with the opcache and ImageMagick extensions 45 - enabled: 43 + function as its only argument; the function should accept two named 44 + parameters: `enabled` - a list of currently enabled extensions and 45 + `all` - the set of all extensions, and return a list of wanted 46 + extensions. For example, a PHP package with all default extensions and 47 + ImageMagick enabled: 46 48 47 49 ```nix 48 - php.withExtensions (e: with e; [ imagick opcache ]) 50 + php.withExtensions ({ enabled, all }: 51 + enabled ++ [ all.imagick ]) 49 52 ``` 50 53 51 - Note that this will give you a package with _only_ opcache and 52 - ImageMagick, none of the other extensions which are enabled by default 53 - in the `php` package will be available. 54 + To exclude some, but not all, of the default extensions, you can 55 + filter the `enabled` list like this: 56 + 57 + ```nix 58 + php.withExtensions ({ enabled, all }: 59 + (lib.filter (e: e != php.extensions.opcache) enabled) 60 + ++ [ all.imagick ]) 61 + ``` 54 62 55 - To enable building on a previous PHP package, the currently enabled 56 - extensions are made available in its `enabledExtensions` 57 - attribute. For example, to generate a package with all default 58 - extensions enabled, except opcache, but with ImageMagick: 63 + To build your list of extensions from the ground up, you can simply 64 + ignore `enabled`: 59 65 60 66 ```nix 61 - php.withExtensions (e: 62 - (lib.filter (e: e != php.extensions.opcache) php.enabledExtensions) 63 - ++ [ e.imagick ]) 67 + php.withExtensions ({ all, ... }: with all; [ opcache imagick ]) 64 68 ``` 69 + 70 + `php.withExtensions` provides extensions by wrapping a minimal php 71 + base package, providing a `php.ini` file listing all extensions to be 72 + loaded. You can access this package through the `php.unwrapped` 73 + attribute; useful if you, for example, need access to the `dev` 74 + output. The generated `php.ini` file can be accessed through the 75 + `php.phpIni` attribute. 65 76 66 77 If you want a PHP build with extra configuration in the `php.ini` 67 78 file, you can use `php.buildEnv`. This function takes two named and ··· 73 84 74 85 ```nix 75 86 php.buildEnv { 76 - extensions = e: with e; [ imagick opcache ]; 87 + extensions = { all, ... }: with all; [ imagick opcache ]; 77 88 extraConfig = "memory_limit=256M"; 78 89 } 79 90 ``` ··· 85 96 86 97 ```nix 87 98 let 88 - myPhp = php.withExtensions (e: with e; [ imagick opcache ]); 99 + myPhp = php.withExtensions ({ all, ... }: with all; [ opcache imagick ]); 89 100 in { 90 101 services.phpfpm.pools."foo".phpPackage = myPhp; 91 102 }; ··· 94 105 ```nix 95 106 let 96 107 myPhp = php.buildEnv { 97 - extensions = e: with e; [ imagick opcache ]; 108 + extensions = { all, ... }: with all; [ imagick opcache ]; 98 109 extraConfig = "memory_limit=256M"; 99 110 }; 100 111 in { ··· 105 116 ##### Example usage with `nix-shell` 106 117 107 118 This brings up a temporary environment that contains a PHP interpreter 108 - with the extensions `imagick` and `opcache` enabled. 119 + with the extensions `imagick` and `opcache` enabled: 109 120 110 121 ```sh 111 - nix-shell -p 'php.buildEnv { extensions = e: with e; [ imagick opcache ]; }' 122 + nix-shell -p 'php.withExtensions ({ all, ... }: with all; [ imagick opcache ])' 112 123 ```
+50 -50
nixos/doc/manual/release-notes/rl-2009.xml
··· 145 145 </listitem> 146 146 <listitem> 147 147 <para> 148 - Since this release there's an easy way to customize your PHP install to get a much smaller 149 - base PHP with only wanted extensions enabled. See the following snippet installing a smaller PHP 150 - with the extensions <literal>imagick</literal>, <literal>opcache</literal> and 148 + Since this release there's an easy way to customize your PHP 149 + install to get a much smaller base PHP with only wanted 150 + extensions enabled. See the following snippet installing a 151 + smaller PHP with the extensions <literal>imagick</literal>, 152 + <literal>opcache</literal>, <literal>pdo</literal> and 151 153 <literal>pdo_mysql</literal> loaded: 152 154 153 155 <programlisting> 154 156 environment.systemPackages = [ 155 - (pkgs.php.buildEnv { extensions = pp: with pp; [ 156 - imagick 157 - opcache 158 - pdo_mysql 159 - ]; }) 157 + (pkgs.php.withExtensions 158 + ({ all, ... }: with all; [ 159 + imagick 160 + opcache 161 + pdo 162 + pdo_mysql 163 + ]) 164 + ) 160 165 ];</programlisting> 161 166 162 - The default <literal>php</literal> attribute hasn't lost any extensions - 163 - the <literal>opcache</literal> extension was added there. 167 + The default <literal>php</literal> attribute hasn't lost any 168 + extensions. The <literal>opcache</literal> extension has been 169 + added. 164 170 165 171 All upstream PHP extensions are available under <package><![CDATA[php.extensions.<name?>]]></package>. 166 172 </para> 167 173 <para> 168 - The updated <literal>php</literal> attribute is now easily customizable to your liking 169 - by using extensions instead of writing config files or changing configure flags. 170 - 171 - Therefore we have removed the following configure flags: 174 + All PHP <literal>config</literal> flags have been removed for 175 + the following reasons: 172 176 173 177 <itemizedlist> 174 - <title>PHP <literal>config</literal> flags that we don't read anymore:</title> 175 - <listitem><para><literal>config.php.argon2</literal></para></listitem> 176 - <listitem><para><literal>config.php.bcmath</literal></para></listitem> 177 - <listitem><para><literal>config.php.bz2</literal></para></listitem> 178 - <listitem><para><literal>config.php.calendar</literal></para></listitem> 179 - <listitem><para><literal>config.php.curl</literal></para></listitem> 180 - <listitem><para><literal>config.php.exif</literal></para></listitem> 181 - <listitem><para><literal>config.php.ftp</literal></para></listitem> 182 - <listitem><para><literal>config.php.gd</literal></para></listitem> 183 - <listitem><para><literal>config.php.gettext</literal></para></listitem> 184 - <listitem><para><literal>config.php.gmp</literal></para></listitem> 185 - <listitem><para><literal>config.php.imap</literal></para></listitem> 186 - <listitem><para><literal>config.php.intl</literal></para></listitem> 187 - <listitem><para><literal>config.php.ldap</literal></para></listitem> 188 - <listitem><para><literal>config.php.libxml2</literal></para></listitem> 189 - <listitem><para><literal>config.php.libzip</literal></para></listitem> 190 - <listitem><para><literal>config.php.mbstring</literal></para></listitem> 191 - <listitem><para><literal>config.php.mysqli</literal></para></listitem> 192 - <listitem><para><literal>config.php.mysqlnd</literal></para></listitem> 193 - <listitem><para><literal>config.php.openssl</literal></para></listitem> 194 - <listitem><para><literal>config.php.pcntl</literal></para></listitem> 195 - <listitem><para><literal>config.php.pdo_mysql</literal></para></listitem> 196 - <listitem><para><literal>config.php.pdo_odbc</literal></para></listitem> 197 - <listitem><para><literal>config.php.pdo_pgsql</literal></para></listitem> 198 - <listitem><para><literal>config.php.phpdbg</literal></para></listitem> 199 - <listitem><para><literal>config.php.postgresql</literal></para></listitem> 200 - <listitem><para><literal>config.php.readline</literal></para></listitem> 201 - <listitem><para><literal>config.php.soap</literal></para></listitem> 202 - <listitem><para><literal>config.php.sockets</literal></para></listitem> 203 - <listitem><para><literal>config.php.sodium</literal></para></listitem> 204 - <listitem><para><literal>config.php.sqlite</literal></para></listitem> 205 - <listitem><para><literal>config.php.tidy</literal></para></listitem> 206 - <listitem><para><literal>config.php.xmlrpc</literal></para></listitem> 207 - <listitem><para><literal>config.php.xsl</literal></para></listitem> 208 - <listitem><para><literal>config.php.zip</literal></para></listitem> 209 - <listitem><para><literal>config.php.zlib</literal></para></listitem> 178 + <listitem> 179 + <para> 180 + The updated <literal>php</literal> attribute is now easily 181 + customizable to your liking by using 182 + <literal>php.withExtensions</literal> or 183 + <literal>php.buildEnv</literal> instead of writing config files 184 + or changing configure flags. 185 + </para> 186 + </listitem> 187 + <listitem> 188 + <para> 189 + The remaining configuration flags can now be set directly on 190 + the <literal>php</literal> attribute. For example, instead of 191 + 192 + <programlisting> 193 + php.override { 194 + config.php.embed = true; 195 + config.php.apxs2 = false; 196 + } 197 + </programlisting> 198 + 199 + you should now write 200 + 201 + <programlisting> 202 + php.override { 203 + embedSupport = true; 204 + apxs2Support = false; 205 + } 206 + </programlisting> 207 + </para> 208 + </listitem> 210 209 </itemizedlist> 210 + 211 211 </para> 212 212 </listitem> 213 213 <listitem>
+1 -1
nixos/modules/services/mail/roundcube.nix
··· 7 7 fpm = config.services.phpfpm.pools.roundcube; 8 8 localDB = cfg.database.host == "localhost"; 9 9 user = cfg.database.username; 10 - phpWithPspell = pkgs.php.withExtensions (e: [ e.pspell ] ++ pkgs.php.enabledExtensions); 10 + phpWithPspell = pkgs.php.withExtensions ({ enabled, all }: [ all.pspell ] ++ enabled); 11 11 in 12 12 { 13 13 options.services.roundcube = {
+2 -2
nixos/modules/services/web-apps/nextcloud.nix
··· 11 11 base = pkgs.php74; 12 12 in 13 13 base.buildEnv { 14 - extensions = e: with e; 15 - base.enabledExtensions ++ [ 14 + extensions = { enabled, all }: with all; 15 + enabled ++ [ 16 16 apcu redis memcached imagick 17 17 ]; 18 18 extraConfig = phpOptionsStr;
+1 -1
nixos/modules/services/web-servers/apache-httpd/default.nix
··· 338 338 } 339 339 '' 340 340 cat ${php}/etc/php.ini > $out 341 - cat ${php}/lib/custom-php.ini > $out 341 + cat ${php.phpIni} > $out 342 342 echo "$options" >> $out 343 343 ''; 344 344
+218 -189
pkgs/development/interpreters/php/default.nix
··· 1 1 # We have tests for PCRE and PHP-FPM in nixos/tests/php/ or 2 2 # both in the same attribute named nixosTests.php 3 3 4 - { callPackage, config, fetchurl, lib, makeWrapper, stdenv, symlinkJoin 5 - , writeText , autoconf, automake, bison, flex, libtool, pkgconfig, re2c 6 - , apacheHttpd, libargon2, libxml2, pcre, pcre2 , systemd, valgrind 7 - }: 4 + { callPackage, lib, stdenv, nixosTests }@_args: 8 5 9 6 let 10 7 generic = 11 - { version 12 - , sha256 13 - , extraPatches ? [] 8 + { callPackage, lib, stdenv, nixosTests, config, fetchurl, makeWrapper 9 + , symlinkJoin, writeText, autoconf, automake, bison, flex, libtool 10 + , pkgconfig, re2c, apacheHttpd, libargon2, libxml2, pcre, pcre2 11 + , systemd, valgrind 14 12 15 - # Sapi flags 16 - , cgiSupport ? config.php.cgi or true 17 - , cliSupport ? config.php.cli or true 18 - , fpmSupport ? config.php.fpm or true 19 - , pearSupport ? config.php.pear or true 20 - , pharSupport ? config.php.phar or true 21 - , phpdbgSupport ? config.php.phpdbg or true 13 + , version 14 + , sha256 15 + , extraPatches ? [] 22 16 17 + # Sapi flags 18 + , cgiSupport ? true 19 + , cliSupport ? true 20 + , fpmSupport ? true 21 + , pearSupport ? true 22 + , pharSupport ? true 23 + , phpdbgSupport ? true 23 24 24 - # Misc flags 25 - , apxs2Support ? config.php.apxs2 or (!stdenv.isDarwin) 26 - , argon2Support ? config.php.argon2 or true 27 - , cgotoSupport ? config.php.cgoto or false 28 - , embedSupport ? config.php.embed or false 29 - , ipv6Support ? config.php.ipv6 or true 30 - , systemdSupport ? config.php.systemd or stdenv.isLinux 31 - , valgrindSupport ? config.php.valgrind or true 32 - , ztsSupport ? (config.php.zts or false) || (apxs2Support) 33 - }: let 34 - pcre' = if (lib.versionAtLeast version "7.3") then pcre2 else pcre; 35 - in stdenv.mkDerivation { 36 - pname = "php"; 25 + # Misc flags 26 + , apxs2Support ? !stdenv.isDarwin 27 + , argon2Support ? true 28 + , cgotoSupport ? false 29 + , embedSupport ? false 30 + , ipv6Support ? true 31 + , systemdSupport ? stdenv.isLinux 32 + , valgrindSupport ? true 33 + , ztsSupport ? apxs2Support 34 + }@args: 35 + let 36 + # buildEnv wraps php to provide additional extensions and 37 + # configuration. Its usage is documented in 38 + # doc/languages-frameworks/php.section.md. 39 + # 40 + # Create a buildEnv with earlier overridden values and 41 + # extensions functions in its closure. This is necessary for 42 + # consecutive calls to buildEnv and overrides to work as 43 + # expected. 44 + mkBuildEnv = prevArgs: prevExtensionFunctions: lib.makeOverridable ( 45 + { extensions ? ({...}: []), extraConfig ? "", ... }@innerArgs: 46 + let 47 + allArgs = args // prevArgs // innerArgs; 48 + filteredArgs = builtins.removeAttrs allArgs [ "extensions" "extraConfig" ]; 49 + php = generic filteredArgs; 37 50 38 - inherit version; 51 + php-packages = (callPackage ../../../top-level/php-packages.nix { 52 + php = phpWithExtensions; 53 + }); 39 54 40 - enableParallelBuilding = true; 55 + allExtensionFunctions = prevExtensionFunctions ++ [ extensions ]; 56 + enabledExtensions = 57 + builtins.foldl' 58 + (state: f: 59 + f { enabled = state; all = php-packages.extensions; }) 60 + [] 61 + allExtensionFunctions; 41 62 42 - nativeBuildInputs = [ autoconf automake bison flex libtool pkgconfig re2c ]; 63 + getExtName = ext: lib.removePrefix "php-" (builtins.parseDrvName ext.name).name; 43 64 44 - buildInputs = 45 - # PCRE extension 46 - [ pcre' ] 65 + # Recursively get a list of all internal dependencies 66 + # for a list of extensions. 67 + getDepsRecursively = extensions: 68 + let 69 + deps = lib.concatMap 70 + (ext: ext.internalDeps or []) 71 + extensions; 72 + in 73 + if ! (deps == []) then 74 + deps ++ (getDepsRecursively deps) 75 + else 76 + deps; 47 77 48 - # Enable sapis 49 - ++ lib.optional pearSupport [ libxml2.dev ] 78 + # Generate extension load configuration snippets from the 79 + # extension parameter. This is an attrset suitable for use 80 + # with textClosureList, which is used to put the strings in 81 + # the right order - if a plugin which is dependent on 82 + # another plugin is placed before its dependency, it will 83 + # fail to load. 84 + extensionTexts = 85 + lib.listToAttrs 86 + (map (ext: 87 + let 88 + extName = getExtName ext; 89 + type = "${lib.optionalString (ext.zendExtension or false) "zend_"}extension"; 90 + in 91 + lib.nameValuePair extName { 92 + text = "${type}=${ext}/lib/php/extensions/${extName}.so"; 93 + deps = lib.optionals (ext ? internalDeps) 94 + (map getExtName ext.internalDeps); 95 + }) 96 + (enabledExtensions ++ (getDepsRecursively enabledExtensions))); 50 97 51 - # Misc deps 52 - ++ lib.optional apxs2Support apacheHttpd 53 - ++ lib.optional argon2Support libargon2 54 - ++ lib.optional systemdSupport systemd 55 - ++ lib.optional valgrindSupport valgrind 56 - ; 98 + extNames = map getExtName enabledExtensions; 99 + extraInit = writeText "php.ini" '' 100 + ${lib.concatStringsSep "\n" 101 + (lib.textClosureList extensionTexts extNames)} 102 + ${extraConfig} 103 + ''; 57 104 58 - CXXFLAGS = lib.optionalString stdenv.cc.isClang "-std=c++11"; 105 + phpWithExtensions = symlinkJoin rec { 106 + name = "php-with-extensions-${version}"; 107 + inherit (php) version; 108 + nativeBuildInputs = [ makeWrapper ]; 109 + passthru = { 110 + buildEnv = mkBuildEnv allArgs allExtensionFunctions; 111 + withExtensions = mkWithExtensions allArgs allExtensionFunctions; 112 + phpIni = "${phpWithExtensions}/lib/php.ini"; 113 + unwrapped = php; 114 + tests = nixosTests.php; 115 + inherit (php-packages) packages extensions; 116 + }; 117 + paths = [ php ]; 118 + postBuild = '' 119 + cp ${extraInit} $out/lib/php.ini 59 120 60 - configureFlags = 61 - # Disable all extensions 62 - [ "--disable-all" ] 121 + wrapProgram $out/bin/php --set PHP_INI_SCAN_DIR $out/lib 63 122 64 - # PCRE 65 - ++ lib.optionals (lib.versionAtLeast version "7.4") [ "--with-external-pcre=${pcre'.dev}" ] 66 - ++ lib.optionals (lib.versions.majorMinor version == "7.3") [ "--with-pcre-regex=${pcre'.dev}" ] 67 - ++ lib.optionals (lib.versionOlder version "7.3") [ "--with-pcre-regex=${pcre'.dev}" ] 68 - ++ [ "PCRE_LIBDIR=${pcre'}" ] 123 + if test -e $out/bin/php-fpm; then 124 + wrapProgram $out/bin/php-fpm --set PHP_INI_SCAN_DIR $out/lib 125 + fi 126 + ''; 127 + }; 128 + in 129 + phpWithExtensions); 69 130 131 + mkWithExtensions = prevArgs: prevExtensionFunctions: extensions: 132 + mkBuildEnv prevArgs prevExtensionFunctions { inherit extensions; }; 70 133 71 - # Enable sapis 72 - ++ lib.optional (!cgiSupport) "--disable-cgi" 73 - ++ lib.optional (!cliSupport) "--disable-cli" 74 - ++ lib.optional fpmSupport "--enable-fpm" 75 - ++ lib.optional pearSupport [ "--with-pear=$(out)/lib/php/pear" "--enable-xml" "--with-libxml" ] 76 - ++ lib.optional (pearSupport && (lib.versionOlder version "7.4")) "--enable-libxml" 77 - ++ lib.optional pharSupport "--enable-phar" 78 - ++ lib.optional phpdbgSupport "--enable-phpdbg" 134 + pcre' = if (lib.versionAtLeast version "7.3") then pcre2 else pcre; 135 + in 136 + stdenv.mkDerivation { 137 + pname = "php"; 138 + 139 + inherit version; 79 140 141 + enableParallelBuilding = true; 80 142 81 - # Misc flags 82 - ++ lib.optional apxs2Support "--with-apxs2=${apacheHttpd.dev}/bin/apxs" 83 - ++ lib.optional argon2Support "--with-password-argon2=${libargon2}" 84 - ++ lib.optional cgotoSupport "--enable-re2c-cgoto" 85 - ++ lib.optional embedSupport "--enable-embed" 86 - ++ lib.optional (!ipv6Support) "--disable-ipv6" 87 - ++ lib.optional systemdSupport "--with-fpm-systemd" 88 - ++ lib.optional valgrindSupport "--with-valgrind=${valgrind.dev}" 89 - ++ lib.optional ztsSupport "--enable-maintainer-zts" 90 - ; 143 + nativeBuildInputs = [ autoconf automake bison flex libtool pkgconfig re2c ]; 91 144 92 - hardeningDisable = [ "bindnow" ]; 145 + buildInputs = 146 + # PCRE extension 147 + [ pcre' ] 93 148 94 - preConfigure = '' 95 - # Don't record the configure flags since this causes unnecessary 96 - # runtime dependencies 97 - for i in main/build-defs.h.in scripts/php-config.in; do 98 - substituteInPlace $i \ 99 - --replace '@CONFIGURE_COMMAND@' '(omitted)' \ 100 - --replace '@CONFIGURE_OPTIONS@' "" \ 101 - --replace '@PHP_LDFLAGS@' "" 102 - done 149 + # Enable sapis 150 + ++ lib.optional pearSupport [ libxml2.dev ] 103 151 104 - export EXTENSION_DIR=$out/lib/php/extensions 152 + # Misc deps 153 + ++ lib.optional apxs2Support apacheHttpd 154 + ++ lib.optional argon2Support libargon2 155 + ++ lib.optional systemdSupport systemd 156 + ++ lib.optional valgrindSupport valgrind 157 + ; 105 158 106 - ./buildconf --copy --force 159 + CXXFLAGS = lib.optionalString stdenv.cc.isClang "-std=c++11"; 107 160 108 - if test -f $src/genfiles; then 109 - ./genfiles 110 - fi 111 - '' + lib.optionalString stdenv.isDarwin '' 112 - substituteInPlace configure --replace "-lstdc++" "-lc++" 113 - ''; 161 + configureFlags = 162 + # Disable all extensions 163 + [ "--disable-all" ] 114 164 115 - postInstall = '' 116 - test -d $out/etc || mkdir $out/etc 117 - cp php.ini-production $out/etc/php.ini 118 - ''; 165 + # PCRE 166 + ++ lib.optionals (lib.versionAtLeast version "7.4") [ "--with-external-pcre=${pcre'.dev}" ] 167 + ++ lib.optionals (lib.versions.majorMinor version == "7.3") [ "--with-pcre-regex=${pcre'.dev}" ] 168 + ++ lib.optionals (lib.versionOlder version "7.3") [ "--with-pcre-regex=${pcre'.dev}" ] 169 + ++ [ "PCRE_LIBDIR=${pcre'}" ] 119 170 120 - postFixup = '' 121 - mkdir -p $dev/bin $dev/share/man/man1 122 - mv $out/bin/phpize $out/bin/php-config $dev/bin/ 123 - mv $out/share/man/man1/phpize.1.gz \ 124 - $out/share/man/man1/php-config.1.gz \ 125 - $dev/share/man/man1/ 126 - ''; 127 171 128 - src = fetchurl { 129 - url = "https://www.php.net/distributions/php-${version}.tar.bz2"; 130 - inherit sha256; 131 - }; 172 + # Enable sapis 173 + ++ lib.optional (!cgiSupport) "--disable-cgi" 174 + ++ lib.optional (!cliSupport) "--disable-cli" 175 + ++ lib.optional fpmSupport "--enable-fpm" 176 + ++ lib.optional pearSupport [ "--with-pear=$(out)/lib/php/pear" "--enable-xml" "--with-libxml" ] 177 + ++ lib.optional (pearSupport && (lib.versionOlder version "7.4")) "--enable-libxml" 178 + ++ lib.optional pharSupport "--enable-phar" 179 + ++ lib.optional phpdbgSupport "--enable-phpdbg" 132 180 133 - patches = [ ./fix-paths-php7.patch ] ++ extraPatches; 134 181 135 - separateDebugInfo = true; 182 + # Misc flags 183 + ++ lib.optional apxs2Support "--with-apxs2=${apacheHttpd.dev}/bin/apxs" 184 + ++ lib.optional argon2Support "--with-password-argon2=${libargon2}" 185 + ++ lib.optional cgotoSupport "--enable-re2c-cgoto" 186 + ++ lib.optional embedSupport "--enable-embed" 187 + ++ lib.optional (!ipv6Support) "--disable-ipv6" 188 + ++ lib.optional systemdSupport "--with-fpm-systemd" 189 + ++ lib.optional valgrindSupport "--with-valgrind=${valgrind.dev}" 190 + ++ lib.optional ztsSupport "--enable-maintainer-zts" 191 + ; 136 192 137 - outputs = [ "out" "dev" ]; 193 + hardeningDisable = [ "bindnow" ]; 138 194 139 - meta = with stdenv.lib; { 140 - description = "An HTML-embedded scripting language"; 141 - homepage = "https://www.php.net/"; 142 - license = licenses.php301; 143 - maintainers = with maintainers; [ globin etu ma27 ]; 144 - platforms = platforms.all; 145 - outputsToInstall = [ "out" "dev" ]; 146 - }; 147 - }; 195 + preConfigure = '' 196 + # Don't record the configure flags since this causes unnecessary 197 + # runtime dependencies 198 + for i in main/build-defs.h.in scripts/php-config.in; do 199 + substituteInPlace $i \ 200 + --replace '@CONFIGURE_COMMAND@' '(omitted)' \ 201 + --replace '@CONFIGURE_OPTIONS@' "" \ 202 + --replace '@PHP_LDFLAGS@' "" 203 + done 148 204 149 - generic' = { version, sha256, self, selfWithExtensions, ... }@args: 150 - let 151 - php = generic (builtins.removeAttrs args [ "self" "selfWithExtensions" ]); 205 + export EXTENSION_DIR=$out/lib/php/extensions 152 206 153 - php-packages = (callPackage ../../../top-level/php-packages.nix { 154 - php = self; 155 - phpWithExtensions = selfWithExtensions; 156 - }); 207 + ./buildconf --copy --force 157 208 158 - buildEnv = { extensions ? (_: []), extraConfig ? "" }: 159 - let 160 - getExtName = ext: lib.removePrefix "php-" (builtins.parseDrvName ext.name).name; 161 - enabledExtensions = extensions php-packages.extensions; 209 + if test -f $src/genfiles; then 210 + ./genfiles 211 + fi 212 + '' + lib.optionalString stdenv.isDarwin '' 213 + substituteInPlace configure --replace "-lstdc++" "-lc++" 214 + ''; 162 215 163 - # Generate extension load configuration snippets from the 164 - # extension parameter. This is an attrset suitable for use 165 - # with textClosureList, which is used to put the strings in 166 - # the right order - if a plugin which is dependent on 167 - # another plugin is placed before its dependency, it will 168 - # fail to load. 169 - extensionTexts = 170 - lib.listToAttrs 171 - (map (ext: 172 - let 173 - extName = getExtName ext; 174 - type = "${lib.optionalString (ext.zendExtension or false) "zend_"}extension"; 175 - in 176 - lib.nameValuePair extName { 177 - text = "${type}=${ext}/lib/php/extensions/${extName}.so"; 178 - deps = lib.optionals (ext ? internalDeps) 179 - (map getExtName ext.internalDeps); 180 - }) 181 - enabledExtensions); 216 + postInstall = '' 217 + test -d $out/etc || mkdir $out/etc 218 + cp php.ini-production $out/etc/php.ini 219 + ''; 182 220 183 - extNames = map getExtName enabledExtensions; 184 - extraInit = writeText "custom-php.ini" '' 185 - ${lib.concatStringsSep "\n" 186 - (lib.textClosureList extensionTexts extNames)} 187 - ${extraConfig} 221 + postFixup = '' 222 + mkdir -p $dev/bin $dev/share/man/man1 223 + mv $out/bin/phpize $out/bin/php-config $dev/bin/ 224 + mv $out/share/man/man1/phpize.1.gz \ 225 + $out/share/man/man1/php-config.1.gz \ 226 + $dev/share/man/man1/ 188 227 ''; 189 - in 190 - symlinkJoin { 191 - name = "php-with-extensions-${version}"; 192 - inherit (php) version; 193 - nativeBuildInputs = [ makeWrapper ]; 194 - passthru = { 195 - inherit buildEnv withExtensions enabledExtensions; 196 - inherit (php-packages) packages extensions; 197 - }; 198 - paths = [ php ]; 199 - postBuild = '' 200 - cp ${extraInit} $out/lib/custom-php.ini 228 + 229 + src = fetchurl { 230 + url = "https://www.php.net/distributions/php-${version}.tar.bz2"; 231 + inherit sha256; 232 + }; 233 + 234 + patches = [ ./fix-paths-php7.patch ] ++ extraPatches; 235 + 236 + separateDebugInfo = true; 201 237 202 - wrapProgram $out/bin/php --set PHP_INI_SCAN_DIR $out/lib 238 + outputs = [ "out" "dev" ]; 203 239 204 - if test -e $out/bin/php-fpm; then 205 - wrapProgram $out/bin/php-fpm --set PHP_INI_SCAN_DIR $out/lib 206 - fi 207 - ''; 240 + passthru = { 241 + buildEnv = mkBuildEnv {} []; 242 + withExtensions = mkWithExtensions {} []; 208 243 }; 209 244 210 - withExtensions = extensions: buildEnv { inherit extensions; }; 211 - in 212 - php.overrideAttrs (_: { 213 - passthru = { 214 - enabledExtensions = []; 215 - inherit buildEnv withExtensions; 216 - inherit (php-packages) packages extensions; 245 + meta = with stdenv.lib; { 246 + description = "An HTML-embedded scripting language"; 247 + homepage = "https://www.php.net/"; 248 + license = licenses.php301; 249 + maintainers = with maintainers; [ globin etu ma27 ]; 250 + platforms = platforms.all; 251 + outputsToInstall = [ "out" "dev" ]; 252 + }; 217 253 }; 218 - }); 219 254 220 - php72base = generic' { 255 + php72base = callPackage generic (_args // { 221 256 version = "7.2.29"; 222 257 sha256 = "08xry2fgqgg8s0ym1hh11wkbr36av3zq1bn4krbciw1b7x8gb8ga"; 223 - self = php72base; 224 - selfWithExtensions = php72; 225 258 226 259 # https://bugs.php.net/bug.php?id=76826 227 260 extraPatches = lib.optional stdenv.isDarwin ./php72-darwin-isfinite.patch; 228 - }; 261 + }); 229 262 230 - php73base = generic' { 263 + php73base = callPackage generic (_args // { 231 264 version = "7.3.16"; 232 265 sha256 = "0bh499v9dfgh9k51w4rird1slb9rh9whp5h37fb84c98d992s1xq"; 233 - self = php73base; 234 - selfWithExtensions = php73; 235 266 236 267 # https://bugs.php.net/bug.php?id=76826 237 268 extraPatches = lib.optional stdenv.isDarwin ./php73-darwin-isfinite.patch; 238 - }; 269 + }); 239 270 240 - php74base = generic' { 271 + php74base = callPackage generic (_args // { 241 272 version = "7.4.4"; 242 273 sha256 = "17w2m4phhpj76x5fx67vgjrlkcczqvky3f5in1kjg2pch90qz3ih"; 243 - self = php74base; 244 - selfWithExtensions = php74; 245 - }; 274 + }); 246 275 247 - defaultPhpExtensions = extensions: with extensions; ([ 276 + defaultPhpExtensions = { all, ... }: with all; ([ 248 277 bcmath calendar curl ctype dom exif fileinfo filter ftp gd 249 278 gettext gmp iconv intl json ldap mbstring mysqli mysqlnd opcache 250 279 openssl pcntl pdo pdo_mysql pdo_odbc pdo_pgsql pdo_sqlite pgsql ··· 252 281 tokenizer xmlreader xmlwriter zip zlib 253 282 ] ++ lib.optionals (!stdenv.isDarwin) [ imap ]); 254 283 255 - defaultPhpExtensionsWithHash = extensions: 256 - (defaultPhpExtensions extensions) ++ [ extensions.hash ]; 284 + defaultPhpExtensionsWithHash = { all, ... }: 285 + (defaultPhpExtensions { inherit all; }) ++ [ all.hash ]; 257 286 258 287 php74 = php74base.withExtensions defaultPhpExtensions; 259 288 php73 = php73base.withExtensions defaultPhpExtensionsWithHash; 260 289 php72 = php72base.withExtensions defaultPhpExtensionsWithHash; 261 290 262 291 in { 263 - inherit php72base php73base php74base php72 php73 php74; 292 + inherit php72 php73 php74; 264 293 }
+12 -12
pkgs/servers/http/unit/default.nix
··· 1 1 { stdenv, fetchFromGitHub, which 2 2 , withPython2 ? false, python2 3 3 , withPython3 ? true, python3, ncurses 4 - , withPHP72 ? false, php72base 5 - , withPHP73 ? true, php73base 4 + , withPHP72 ? false, php72 5 + , withPHP73 ? true, php73 6 6 , withPerl528 ? false, perl528 7 7 , withPerl530 ? true, perl530 8 8 , withPerldevel ? false, perldevel ··· 18 18 19 19 let 20 20 phpConfig = { 21 - config.php.embed = true; 22 - config.php.apxs2 = false; 23 - config.php.systemd = false; 24 - config.php.phpdbg = false; 25 - config.php.cgi = false; 26 - config.php.fpm = false; 21 + embedSupport = true; 22 + apxs2Support = false; 23 + systemdSupport = false; 24 + phpdbgSupport = false; 25 + cgiSupport = false; 26 + fpmSupport = false; 27 27 }; 28 28 29 - php72-unit = php72base.override phpConfig; 30 - php73-unit = php73base.override phpConfig; 29 + php72-unit = php72.override phpConfig; 30 + php73-unit = php73.override phpConfig; 31 31 in stdenv.mkDerivation rec { 32 32 version = "1.16.0"; 33 33 pname = "unit"; ··· 71 71 postConfigure = '' 72 72 ${optionalString withPython2 "./configure python --module=python2 --config=${python2}/bin/python2-config --lib-path=${python2}/lib"} 73 73 ${optionalString withPython3 "./configure python --module=python3 --config=${python3}/bin/python3-config --lib-path=${python3}/lib"} 74 - ${optionalString withPHP72 "./configure php --module=php72 --config=${php72-unit.dev}/bin/php-config --lib-path=${php72-unit}/lib"} 75 - ${optionalString withPHP73 "./configure php --module=php73 --config=${php73-unit.dev}/bin/php-config --lib-path=${php73-unit}/lib"} 74 + ${optionalString withPHP72 "./configure php --module=php72 --config=${php72-unit.unwrapped.dev}/bin/php-config --lib-path=${php72-unit}/lib"} 75 + ${optionalString withPHP73 "./configure php --module=php73 --config=${php73-unit.unwrapped.dev}/bin/php-config --lib-path=${php73-unit}/lib"} 76 76 ${optionalString withPerl528 "./configure perl --module=perl528 --perl=${perl528}/bin/perl"} 77 77 ${optionalString withPerl530 "./configure perl --module=perl530 --perl=${perl530}/bin/perl"} 78 78 ${optionalString withPerldevel "./configure perl --module=perldev --perl=${perldevel}/bin/perl"}
+2 -2
pkgs/servers/uwsgi/default.nix
··· 8 8 }: 9 9 10 10 let php-embed = php.override { 11 - config.php.embed = true; 12 - config.php.apxs2 = false; 11 + embedSupport = true; 12 + apxs2Support = false; 13 13 }; 14 14 15 15 pythonPlugin = pkg : lib.nameValuePair "python${if pkg.isPy2 then "2" else "3"}" {
+25 -23
pkgs/top-level/aliases.nix
··· 339 339 pg_tmp = ephemeralpg; # added 2018-01-16 340 340 341 341 php-embed = throw '' 342 - php*-embed has been dropped, you can build the same package by using 343 - something similar with this following snippet: 344 - (php74.override { config.php.embed = true; config.php.apxs2 = false; }) 342 + php*-embed has been dropped, you can build something similar 343 + with the following snippet: 344 + php74.override { embedSupport = true; apxs2Support = false; } 345 345 ''; # added 2020-04-01 346 346 php72-embed = php-embed; # added 2020-04-01 347 347 php73-embed = php-embed; # added 2020-04-01 348 348 php74-embed = php-embed; # added 2020-04-01 349 349 350 350 phpPackages-embed = throw '' 351 - php*Packages-embed has been dropped, you can build the same package by using 352 - something similar with this following snippet: 353 - (php74.override { config.php.embed = true; config.php.apxs2 = false; }).packages 351 + php*Packages-embed has been dropped, you can build something 352 + similar with the following snippet: 353 + (php74.override { embedSupport = true; apxs2Support = false; }).packages 354 354 ''; # added 2020-04-01 355 355 php74Packages-embed = phpPackages-embed; 356 356 php73Packages-embed = phpPackages-embed; 357 357 php72Packages-embed = phpPackages-embed; 358 358 359 359 php-unit = throw '' 360 - php*-unit has been dropped, you can build the same package by using 361 - something similar with this following snippet: 362 - (php74.override { 363 - config.php.embed = true; 364 - config.php.apxs2 = false; 365 - config.php.systemd = false; 366 - config.php.phpdbg = false; 367 - config.php.cgi = false; 368 - config.php.fpm = false; }) 360 + php*-unit has been dropped, you can build something similar with 361 + the following snippet: 362 + php74.override { 363 + embedSupport = true; 364 + apxs2Support = false; 365 + systemdSupport = false; 366 + phpdbgSupport = false; 367 + cgiSupport = false; 368 + fpmSupport = false; 369 + } 369 370 ''; # added 2020-04-01 370 371 php72-unit = php-unit; # added 2020-04-01 371 372 php73-unit = php-unit; # added 2020-04-01 372 373 php74-unit = php-unit; # added 2020-04-01 373 374 374 375 phpPackages-unit = throw '' 375 - php*Packages-unit has been dropped, you can build the same package by using 376 - something similar with this following snippet: 376 + php*Packages-unit has been dropped, you can build something 377 + similar with this following snippet: 377 378 (php74.override { 378 - config.php.embed = true; 379 - config.php.apxs2 = false; 380 - config.php.systemd = false; 381 - config.php.phpdbg = false; 382 - config.php.cgi = false; 383 - config.php.fpm = false; }).packages 379 + embedSupport = true; 380 + apxs2Support = false; 381 + systemdSupport = false; 382 + phpdbgSupport = false; 383 + cgiSupport = false; 384 + fpmSupport = false; 385 + }).packages 384 386 ''; # added 2020-04-01 385 387 php74Packages-unit = phpPackages-unit; 386 388 php73Packages-unit = phpPackages-unit;
+2 -2
pkgs/top-level/all-packages.nix
··· 9457 9457 php73Extensions = recurseIntoAttrs php73.extensions; 9458 9458 php74Extensions = recurseIntoAttrs php74.extensions; 9459 9459 9460 - inherit (callPackages ../development/interpreters/php { 9460 + inherit (callPackage ../development/interpreters/php { 9461 9461 stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv; 9462 - }) php74 php73 php72 php74base php73base php72base; 9462 + }) php74 php73 php72; 9463 9463 9464 9464 picoc = callPackage ../development/interpreters/picoc {}; 9465 9465
+13 -12
pkgs/top-level/php-packages.nix
··· 1 - { stdenv, lib, pkgs, fetchgit, php, phpWithExtensions, autoconf, pkgconfig, re2c 1 + { stdenv, lib, pkgs, fetchgit, php, autoconf, pkgconfig, re2c 2 2 , gettext, bzip2, curl, libxml2, openssl, gmp, icu, oniguruma, libsodium 3 3 , html-tidy, libzip, zlib, pcre, pcre2, libxslt, aspell, openldap, cyrus_sasl 4 4 , uwimap, pam, libiconv, enchant1, libXpm, gd, libwebp, libjpeg, libpng ··· 8 8 9 9 let 10 10 buildPecl = import ../build-support/build-pecl.nix { 11 - inherit php lib; 11 + php = php.unwrapped; 12 + inherit lib; 12 13 inherit (pkgs) stdenv autoreconfHook fetchurl re2c; 13 14 }; 14 15 ··· 43 44 installPhase = '' 44 45 mkdir -p $out/bin 45 46 install -D $src $out/libexec/box/box.phar 46 - makeWrapper ${phpWithExtensions}/bin/php $out/bin/box \ 47 + makeWrapper ${php}/bin/php $out/bin/box \ 47 48 --add-flags "-d phar.readonly=0 $out/libexec/box/box.phar" 48 49 ''; 49 50 ··· 71 72 installPhase = '' 72 73 mkdir -p $out/bin 73 74 install -D $src $out/libexec/composer/composer.phar 74 - makeWrapper ${phpWithExtensions}/bin/php $out/bin/composer \ 75 + makeWrapper ${php}/bin/php $out/bin/composer \ 75 76 --add-flags "$out/libexec/composer/composer.phar" \ 76 77 --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.unzip ]} 77 78 ''; ··· 163 164 installPhase = '' 164 165 mkdir -p $out/bin 165 166 install -D $src $out/libexec/phpcbf/phpcbf.phar 166 - makeWrapper ${phpWithExtensions}/bin/php $out/bin/phpcbf \ 167 + makeWrapper ${php}/bin/php $out/bin/phpcbf \ 167 168 --add-flags "$out/libexec/phpcbf/phpcbf.phar" 168 169 ''; 169 170 ··· 190 191 installPhase = '' 191 192 mkdir -p $out/bin 192 193 install -D $src $out/libexec/phpcs/phpcs.phar 193 - makeWrapper ${phpWithExtensions}/bin/php $out/bin/phpcs \ 194 + makeWrapper ${php}/bin/php $out/bin/phpcs \ 194 195 --add-flags "$out/libexec/phpcs/phpcs.phar" 195 196 ''; 196 197 ··· 217 218 installPhase = '' 218 219 mkdir -p $out/bin 219 220 install -D $src $out/libexec/phpstan/phpstan.phar 220 - makeWrapper ${phpWithExtensions}/bin/php $out/bin/phpstan \ 221 + makeWrapper ${php}/bin/php $out/bin/phpstan \ 221 222 --add-flags "$out/libexec/phpstan/phpstan.phar" 222 223 ''; 223 224 ··· 537 538 }; 538 539 539 540 pdo_oci = buildPecl rec { 540 - inherit (php) src version; 541 + inherit (php.unwrapped) src version; 541 542 542 543 pname = "pdo_oci"; 543 544 sourceRoot = "php-${version}/ext/pdo_oci"; ··· 548 549 internalDeps = [ php.extensions.pdo ]; 549 550 550 551 postPatch = '' 551 - sed -i -e 's|OCISDKMANINC=`.*$|OCISDKMANINC="${pkgs.oracle-instantclient.dev}/include"|' config.m4 552 - ''; 552 + sed -i -e 's|OCISDKMANINC=`.*$|OCISDKMANINC="${pkgs.oracle-instantclient.dev}/include"|' config.m4 553 + ''; 553 554 }; 554 555 555 556 pdo_sqlsrv = buildPecl { ··· 746 747 pname = "php-${name}"; 747 748 extensionName = name; 748 749 749 - inherit (php) version src; 750 + inherit (php.unwrapped) version src; 750 751 sourceRoot = "php-${php.version}/ext/${name}"; 751 752 752 753 enableParallelBuilding = true; 753 - nativeBuildInputs = [ php autoconf pkgconfig re2c ]; 754 + nativeBuildInputs = [ php.unwrapped autoconf pkgconfig re2c ]; 754 755 inherit configureFlags internalDeps buildInputs 755 756 zendExtension doCheck; 756 757