summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorWout Mertens <Wout.Mertens@gmail.com>2019-01-21 08:35:49 +0100
committerGitHub <noreply@github.com>2019-01-21 08:35:49 +0100
commite445eabbe845dbbaa266f9f00d3be34a2d5abd20 (patch)
tree75de00d8735c9c5df35062ce0fffd7b5354e35d3 /nixos/modules
parentd75457c802a724b296dc9d0cc5059c41a60fc61a (diff)
parent69936b56556a8f808812ca22ecc7fb62d988b1da (diff)
downloadnixpkgs-e445eabbe845dbbaa266f9f00d3be34a2d5abd20.tar
nixpkgs-e445eabbe845dbbaa266f9f00d3be34a2d5abd20.tar.gz
nixpkgs-e445eabbe845dbbaa266f9f00d3be34a2d5abd20.tar.bz2
nixpkgs-e445eabbe845dbbaa266f9f00d3be34a2d5abd20.tar.lz
nixpkgs-e445eabbe845dbbaa266f9f00d3be34a2d5abd20.tar.xz
nixpkgs-e445eabbe845dbbaa266f9f00d3be34a2d5abd20.tar.zst
nixpkgs-e445eabbe845dbbaa266f9f00d3be34a2d5abd20.zip
Merge pull request #41440 from wmertens/php-per-pool
phpfpm: allow configuring PHP package per-pool
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/services/web-servers/phpfpm/default.nix31
-rw-r--r--nixos/modules/services/web-servers/phpfpm/pool-options.nix15
2 files changed, 35 insertions, 11 deletions
diff --git a/nixos/modules/services/web-servers/phpfpm/default.nix b/nixos/modules/services/web-servers/phpfpm/default.nix
index e1f4ff5db7f..152c89a2cae 100644
--- a/nixos/modules/services/web-servers/phpfpm/default.nix
+++ b/nixos/modules/services/web-servers/phpfpm/default.nix
@@ -8,21 +8,31 @@ let
 
   stateDir = "/run/phpfpm";
 
-  poolConfigs = cfg.poolConfigs // mapAttrs mkPool cfg.pools;
+  poolConfigs =
+    (mapAttrs mapPoolConfig cfg.poolConfigs) //
+    (mapAttrs mapPool cfg.pools);
 
-  mkPool = n: p: ''
-    listen = ${p.listen}
-    ${p.extraConfig}
-  '';
+  mapPoolConfig = n: p: {
+    phpPackage = cfg.phpPackage;
+    config = p;
+  };
+
+  mapPool = n: p: {
+    phpPackage = p.phpPackage;
+    config = ''
+      listen = ${p.listen}
+      ${p.extraConfig}
+    '';
+  };
 
-  fpmCfgFile = pool: poolConfig: pkgs.writeText "phpfpm-${pool}.conf" ''
+  fpmCfgFile = pool: conf: pkgs.writeText "phpfpm-${pool}.conf" ''
     [global]
     error_log = syslog
     daemonize = no
     ${cfg.extraConfig}
 
     [${pool}]
-    ${poolConfig}
+    ${conf}
   '';
 
   phpIni = pkgs.runCommand "php.ini" {
@@ -97,13 +107,14 @@ in {
 
       pools = mkOption {
         type = types.attrsOf (types.submodule (import ./pool-options.nix {
-          inherit lib;
+          inherit lib config;
         }));
         default = {};
         example = literalExample ''
          {
            mypool = {
              listen = "/path/to/unix/socket";
+             phpPackage = pkgs.php;
              extraConfig = '''
                user = nobody
                pm = dynamic
@@ -144,7 +155,7 @@ in {
           mkdir -p ${stateDir}
         '';
         serviceConfig = let
-          cfgFile = fpmCfgFile pool poolConfig;
+          cfgFile = fpmCfgFile pool poolConfig.config;
         in {
           Slice = "phpfpm.slice";
           PrivateDevices = true;
@@ -153,7 +164,7 @@ in {
           # XXX: We need AF_NETLINK to make the sendmail SUID binary from postfix work
           RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK";
           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";
         };
       }
diff --git a/nixos/modules/services/web-servers/phpfpm/pool-options.nix b/nixos/modules/services/web-servers/phpfpm/pool-options.nix
index cc688c2c48a..40c83cddb95 100644
--- a/nixos/modules/services/web-servers/phpfpm/pool-options.nix
+++ b/nixos/modules/services/web-servers/phpfpm/pool-options.nix
@@ -1,4 +1,8 @@
-{ lib }:
+{ lib, config }:
+
+let
+  fpmCfg = config.services.phpfpm;
+in
 
 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 {
       type = types.lines;
       example = ''