Merge pull request #41440 from wmertens/php-per-pool

phpfpm: allow configuring PHP package per-pool
This commit is contained in:
Wout Mertens 2019-01-21 08:35:49 +01:00 committed by GitHub
commit e445eabbe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 11 deletions

View File

@ -8,21 +8,31 @@ let
stateDir = "/run/phpfpm"; stateDir = "/run/phpfpm";
poolConfigs = cfg.poolConfigs // mapAttrs mkPool cfg.pools; poolConfigs =
(mapAttrs mapPoolConfig cfg.poolConfigs) //
(mapAttrs mapPool cfg.pools);
mkPool = n: p: '' mapPoolConfig = n: p: {
listen = ${p.listen} phpPackage = cfg.phpPackage;
${p.extraConfig} config = p;
''; };
fpmCfgFile = pool: poolConfig: pkgs.writeText "phpfpm-${pool}.conf" '' mapPool = n: p: {
phpPackage = p.phpPackage;
config = ''
listen = ${p.listen}
${p.extraConfig}
'';
};
fpmCfgFile = pool: conf: pkgs.writeText "phpfpm-${pool}.conf" ''
[global] [global]
error_log = syslog error_log = syslog
daemonize = no daemonize = no
${cfg.extraConfig} ${cfg.extraConfig}
[${pool}] [${pool}]
${poolConfig} ${conf}
''; '';
phpIni = pkgs.runCommand "php.ini" { phpIni = pkgs.runCommand "php.ini" {
@ -97,13 +107,14 @@ in {
pools = mkOption { pools = mkOption {
type = types.attrsOf (types.submodule (import ./pool-options.nix { type = types.attrsOf (types.submodule (import ./pool-options.nix {
inherit lib; inherit lib config;
})); }));
default = {}; default = {};
example = literalExample '' example = literalExample ''
{ {
mypool = { mypool = {
listen = "/path/to/unix/socket"; listen = "/path/to/unix/socket";
phpPackage = pkgs.php;
extraConfig = ''' extraConfig = '''
user = nobody user = nobody
pm = dynamic pm = dynamic
@ -144,7 +155,7 @@ in {
mkdir -p ${stateDir} mkdir -p ${stateDir}
''; '';
serviceConfig = let serviceConfig = let
cfgFile = fpmCfgFile pool poolConfig; cfgFile = fpmCfgFile pool poolConfig.config;
in { in {
Slice = "phpfpm.slice"; Slice = "phpfpm.slice";
PrivateDevices = true; PrivateDevices = true;
@ -153,7 +164,7 @@ in {
# XXX: We need AF_NETLINK to make the sendmail SUID binary from postfix work # XXX: We need AF_NETLINK to make the sendmail SUID binary from postfix work
RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK"; RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK";
Type = "notify"; Type = "notify";
ExecStart = "${cfg.phpPackage}/bin/php-fpm -y ${cfgFile} -c ${phpIni}"; ExecStart = "${poolConfig.phpPackage}/bin/php-fpm -y ${cfgFile} -c ${phpIni}";
ExecReload = "${pkgs.coreutils}/bin/kill -USR2 $MAINPID"; ExecReload = "${pkgs.coreutils}/bin/kill -USR2 $MAINPID";
}; };
} }

View File

@ -1,4 +1,8 @@
{ lib }: { lib, config }:
let
fpmCfg = config.services.phpfpm;
in
with lib; { with lib; {
@ -12,6 +16,15 @@ with lib; {
''; '';
}; };
phpPackage = mkOption {
type = types.package;
default = fpmCfg.phpPackage;
defaultText = "config.services.phpfpm.phpPackage";
description = ''
The PHP package to use for running this PHP-FPM pool.
'';
};
extraConfig = mkOption { extraConfig = mkOption {
type = types.lines; type = types.lines;
example = '' example = ''