Support multiple versions of PHP in phpfpm service #573
-
|
I made a custom service for PHP-FPM earlier this year, for a "Drupal Flake" project that provides an easy local dev environment for Drupal. In my service, I made an option to select from different PHP versions -- we use this so we can test updating the php environments for dozens of Drupal sites and upgrade them one at a time. The project is here: https://www.drupal.org/project/drupal_flake When the phpfpm service got added to services-flake, this caused a namespace collision on our project, so I was looking to move the Drupal Flake's config to use the upstream one -- but it does not provide any ability to specify php version, or add additional modules, etc. So instead I just renamed my service to avoid the name collision. It's now here: https://github.com/freelock/drupal-flake/blob/main/template/.services/php-fpm.nix Is this a feature others are interested in? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
From what I see in your custom { config, … }:
let
finalPkgs = if config ? pkgs then config.pkgs else pkgs;
phpPackageFor = version: finalPkgs.buildEnv {
name = "phpEnv";
paths = if version == "php74" then [
php
php.packages.composer
finalPkgs.mysql-client
] ++ lib.optional (finalPkgs ? drush) finalPkgs.drush
else [
php
php.packages.composer
php.packages.phpstan
php.packages.php-codesniffer
finalPkgs.phpunit
finalPkgs.mysql-client
];
};
in
{
services.phpfpm."php1" = {
enable = true;
package = phpPackageFor "php74";
};
services.phpfpm."php2" = {
enable = true;
package = phpPackageFor "php<version>";
};
} |
Beta Was this translation helpful? Give feedback.
From what I see in your custom
phpfpmdefinition,phpVersionlets you conditionally define thepackageused for the service. This looks like an implementation detail that is better off kept alongside the service usage. For example, you can achieve the same goal withphpfpmdefined in services-flake: