nixos/phpfpm: allow configuring php.ini files per-pool

This commit is contained in:
Aaron Andersen 2019-02-13 19:58:02 -05:00
parent 01d8894c4d
commit 5eef3590ae
2 changed files with 15 additions and 3 deletions

View File

@ -14,11 +14,13 @@ let
mapPoolConfig = n: p: { mapPoolConfig = n: p: {
phpPackage = cfg.phpPackage; phpPackage = cfg.phpPackage;
phpOptions = cfg.phpOptions;
config = p; config = p;
}; };
mapPool = n: p: { mapPool = n: p: {
phpPackage = p.phpPackage; phpPackage = p.phpPackage;
phpOptions = p.phpOptions;
config = '' config = ''
listen = ${p.listen} listen = ${p.listen}
${p.extraConfig} ${p.extraConfig}
@ -35,8 +37,8 @@ let
${conf} ${conf}
''; '';
phpIni = pkgs.runCommand "php.ini" { phpIni = pool: pkgs.runCommand "php.ini" {
inherit (cfg) phpPackage phpOptions; inherit (pool) phpPackage phpOptions;
nixDefaults = '' nixDefaults = ''
sendmail_path = "/run/wrappers/bin/sendmail -t -i" sendmail_path = "/run/wrappers/bin/sendmail -t -i"
''; '';
@ -156,6 +158,7 @@ in {
''; '';
serviceConfig = let serviceConfig = let
cfgFile = fpmCfgFile pool poolConfig.config; cfgFile = fpmCfgFile pool poolConfig.config;
iniFile = phpIni poolConfig;
in { in {
Slice = "phpfpm.slice"; Slice = "phpfpm.slice";
PrivateDevices = true; PrivateDevices = true;
@ -164,7 +167,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 = "${poolConfig.phpPackage}/bin/php-fpm -y ${cfgFile} -c ${phpIni}"; ExecStart = "${poolConfig.phpPackage}/bin/php-fpm -y ${cfgFile} -c ${iniFile}";
ExecReload = "${pkgs.coreutils}/bin/kill -USR2 $MAINPID"; ExecReload = "${pkgs.coreutils}/bin/kill -USR2 $MAINPID";
}; };
} }

View File

@ -25,6 +25,15 @@ with lib; {
''; '';
}; };
phpOptions = mkOption {
type = types.lines;
default = fpmCfg.phpOptions;
defaultText = "config.services.phpfpm.phpOptions";
description = ''
"Options appended to the PHP configuration file <filename>php.ini</filename> used for this PHP-FPM pool."
'';
};
extraConfig = mkOption { extraConfig = mkOption {
type = types.lines; type = types.lines;
example = '' example = ''