1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-01-22 14:45:27 +00:00

php: Document withExtensions + general improvements

This commit is contained in:
talyz 2020-04-03 18:56:12 +02:00
parent b4d289a7ae
commit b5c59cebc6
No known key found for this signature in database
GPG key ID: 2DED2151F4671A2B
2 changed files with 52 additions and 19 deletions

View file

@ -21,34 +21,67 @@ of a given NixOS release will be included in that release of
NixOS. See [PHP Supported NixOS. See [PHP Supported
Versions](https://www.php.net/supported-versions.php). Versions](https://www.php.net/supported-versions.php).
For packages we have `php.packages` that contains packages related Interactive tools built on PHP are put in `php.packages`; composer is
for human interaction, notable example is `php.packages.composer`. for example available at `php.packages.composer`.
For extensions we have `php.extensions` that contains most upstream Most extensions that come with PHP, as well as some popular
extensions as separate attributes as well some additional extensions third-party ones, are available in `php.extensions`; for example, the
that tend to be popular, notable example is: `php.extensions.imagick`. opcache extension shipped with PHP is available at
`php.extensions.opcache` and the third-party ImageMagick extension at
`php.extensions.imagick`.
The different versions of PHP that nixpkgs fetch is located under The different versions of PHP that nixpkgs provides is located under
attributes named based on major and minor version number; e.g., attributes named based on major and minor version number; e.g.,
`php74` is PHP 7.4 with commonly used extensions installed, `php74` is PHP 7.4 with commonly used extensions installed,
`php74base` is the same PHP runtime without extensions. `php74base` is the same PHP runtime without extensions.
#### Installing PHP with packages #### Installing PHP with packages
There's two majorly different parts of the PHP ecosystem in NixOS: A PHP package with specific extensions enabled can be built using
- Command line utilities for human interaction. These comes from the `php.withExtensions`. This is a function which accepts an anonymous
`php.packages.*` attributes. function as its only argument; the function should take one argument,
- PHP environments with different extensions enabled. These are the set of all extensions, and return a list of wanted extensions. For
composed with `php.buildEnv` using an additional configuration file. example, a PHP package with the opcache and ImageMagick extensions
enabled:
```nix
php.withExtensions (e: with e; [ imagick opcache ])
```
If you want a PHP build with extra configuration in the `php.ini`
file, you can use `php.buildEnv`. This function takes two named and
optional parameters: `extensions` and `extraConfig`. `extensions`
takes an extension specification equivalent to that of
`php.withExtensions`, `extraConfig` a string of additional `php.ini`
configuration parameters. For example, a PHP package with the opcache
and ImageMagick extensions enabled, and `memory_limit` set to `256M`:
```nix
php.buildEnv {
extensions = e: with e; [ imagick opcache ];
extraConfig = "memory_limit=256M";
}
```
##### Example setup for `phpfpm` ##### Example setup for `phpfpm`
Example to build a PHP with the extensions `imagick` and `opcache` You can use the previous examples in a `phpfpm` pool called `foo` as
enabled. Then to configure it for the "foo" `phpfpm` pool: follows:
```nix ```nix
let let
myPhp = php.buildEnv { exts = pp: with pp; [ imagick opcache ]; }; myPhp = php.withExtensions (e: with e; [ imagick opcache ]);
in {
services.phpfpm.pools."foo".phpPackage = myPhp;
};
```
```nix
let
myPhp = php.buildEnv {
extensions = e: with e; [ imagick opcache ];
extraConfig = "memory_limit=256M";
};
in { in {
services.phpfpm.pools."foo".phpPackage = myPhp; services.phpfpm.pools."foo".phpPackage = myPhp;
}; };
@ -60,5 +93,5 @@ This brings up a temporary environment that contains a PHP interpreter
with the extensions `imagick` and `opcache` enabled. with the extensions `imagick` and `opcache` enabled.
```sh ```sh
nix-shell -p 'php.buildEnv { exts = pp: with pp; [ imagick opcache ]; }' nix-shell -p 'php.buildEnv { extensions = e: with e; [ imagick opcache ]; }'
``` ```

View file

@ -26,8 +26,7 @@ in
{ {
inherit buildPecl; inherit buildPecl;
# Packages are an attribute set meant for for human interaction and not # This is a set of interactive tools based on PHP.
# extensions for the language itself.
packages = { packages = {
box = mkDerivation rec { box = mkDerivation rec {
version = "2.7.5"; version = "2.7.5";
@ -293,8 +292,9 @@ in
# Extensions are an attribute set meant for for PHP extensions that extend the # This is a set of PHP extensions meant to be used in php.buildEnv
# language rather than human interaction. # or php.withExtensions to extend the functionality of the PHP
# interpreter.
extensions = { extensions = {
apcu = buildPecl { apcu = buildPecl {
version = "5.1.18"; version = "5.1.18";