aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/services/web-servers
diff options
context:
space:
mode:
authorAaron Andersen <aaron@fosslib.net>2019-08-07 22:36:49 -0400
committerAaron Andersen <aaron@fosslib.net>2019-08-23 07:56:27 -0400
commit400c6aac71fb2e190769c288c098d05b258c7543 (patch)
tree24b427392c5557b5f9f96e6eb600317d474d5627 /nixos/modules/services/web-servers
parentd2db3a338c644bfa472005be61323b69b5d29419 (diff)
nixos/phpfpm: deprecate extraConfig options in favor of settings options
Diffstat (limited to 'nixos/modules/services/web-servers')
-rw-r--r--nixos/modules/services/web-servers/phpfpm/default.nix123
1 files changed, 93 insertions, 30 deletions
diff --git a/nixos/modules/services/web-servers/phpfpm/default.nix b/nixos/modules/services/web-servers/phpfpm/default.nix
index 8e8616d925b..e95e71e0d99 100644
--- a/nixos/modules/services/web-servers/phpfpm/default.nix
+++ b/nixos/modules/services/web-servers/phpfpm/default.nix
@@ -7,17 +7,20 @@ let
runtimeDir = "/run/phpfpm";
+ toStr = value:
+ if true == value then "yes"
+ else if false == value then "no"
+ else toString value;
+
fpmCfgFile = pool: poolOpts: pkgs.writeText "phpfpm-${pool}.conf" ''
[global]
- error_log = syslog
- daemonize = no
- ${cfg.extraConfig}
+ ${concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.settings)}
+ ${optionalString (cfg.extraConfig != null) cfg.extraConfig}
[${pool}]
- listen = ${poolOpts.socket}
- user = ${poolOpts.user}
- group = ${poolOpts.group}
- ${poolOpts.extraConfig}
+ ${concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${toStr v}") poolOpts.settings)}
+ ${concatStringsSep "\n" (mapAttrsToList (n: v: "env[${n}] = ${toStr v}") poolOpts.phpEnv)}
+ ${optionalString (poolOpts.extraConfig != null) poolOpts.extraConfig}
'';
phpIni = poolOpts: pkgs.runCommand "php.ini" {
@@ -31,7 +34,7 @@ let
cat $phpPackage/etc/php.ini $nixDefaultsPath $phpOptionsPath > $out
'';
- poolOpts = { lib, name, ... }:
+ poolOpts = { name, ... }:
let
poolOpts = cfg.pools."${name}";
in
@@ -73,6 +76,22 @@ let
'';
};
+ phpEnv = lib.mkOption {
+ type = with types; attrsOf str;
+ default = {};
+ description = ''
+ Environment variables used for this PHP-FPM pool.
+ '';
+ example = literalExample ''
+ {
+ HOSTNAME = "$HOSTNAME";
+ TMP = "/tmp";
+ TMPDIR = "/tmp";
+ TEMP = "/tmp";
+ }
+ '';
+ };
+
user = mkOption {
type = types.str;
description = "User account under which this pool runs.";
@@ -83,17 +102,30 @@ let
description = "Group account under which this pool runs.";
};
- extraConfig = mkOption {
- type = types.lines;
- example = ''
- pm = dynamic
- pm.max_children = 75
- pm.start_servers = 10
- pm.min_spare_servers = 5
- pm.max_spare_servers = 20
- pm.max_requests = 500
+ settings = mkOption {
+ type = with types; attrsOf (oneOf [ str int bool ]);
+ default = {};
+ description = ''
+ PHP-FPM pool directives. Refer to the "List of pool directives" section of
+ <link xlink:href="https://www.php.net/manual/en/install.fpm.configuration.php"/>
+ for details. Note that settings names must be enclosed in quotes (e.g.
+ <literal>"pm.max_children"</literal> instead of <literal>pm.max_children</literal>).
+ '';
+ example = literalExample ''
+ {
+ "pm" = "dynamic";
+ "pm.max_children" = 75;
+ "pm.start_servers" = 10;
+ "pm.min_spare_servers" = 5;
+ "pm.max_spare_servers" = 20;
+ "pm.max_requests" = 500;
+ }
'';
+ };
+ extraConfig = mkOption {
+ type = with types; nullOr lines;
+ default = null;
description = ''
Extra lines that go into the pool configuration.
See the documentation on <literal>php-fpm.conf</literal> for
@@ -105,6 +137,12 @@ let
config = {
socket = if poolOpts.listen == "" then "${runtimeDir}/${name}.sock" else poolOpts.listen;
group = mkDefault poolOpts.user;
+
+ settings = mapAttrs (name: mkDefault){
+ listen = poolOpts.socket;
+ user = poolOpts.user;
+ group = poolOpts.group;
+ };
};
};
@@ -112,9 +150,22 @@ in {
options = {
services.phpfpm = {
+ settings = mkOption {
+ type = with types; attrsOf (oneOf [ str int bool ]);
+ default = {};
+ description = ''
+ PHP-FPM global directives. Refer to the "List of global php-fpm.conf directives" section of
+ <link xlink:href="https://www.php.net/manual/en/install.fpm.configuration.php"/>
+ for details. Note that settings names must be enclosed in quotes (e.g.
+ <literal>"pm.max_children"</literal> instead of <literal>pm.max_children</literal>).
+ You need not specify the options <literal>error_log</literal> or
+ <literal>daemonize</literal> here, since they are generated by NixOS.
+ '';
+ };
+
extraConfig = mkOption {
- type = types.lines;
- default = "";
+ type = with types; nullOr lines;
+ default = null;
description = ''
Extra configuration that should be put in the global section of
the PHP-FPM configuration file. Do not specify the options
@@ -140,8 +191,9 @@ in {
''
date.timezone = "CET"
'';
- description =
- "Options appended to the PHP configuration file <filename>php.ini</filename>.";
+ description = ''
+ Options appended to the PHP configuration file <filename>php.ini</filename>.
+ '';
};
pools = mkOption {
@@ -153,13 +205,13 @@ in {
user = "php";
group = "php";
phpPackage = pkgs.php;
- extraConfig = '''
- pm = dynamic
- pm.max_children = 75
- pm.start_servers = 10
- pm.min_spare_servers = 5
- pm.max_spare_servers = 20
- pm.max_requests = 500
+ settings = '''
+ "pm" = "dynamic";
+ "pm.max_children" = 75;
+ "pm.start_servers" = 10;
+ "pm.min_spare_servers" = 5;
+ "pm.max_spare_servers" = 20;
+ "pm.max_requests" = 500;
''';
}
}'';
@@ -175,10 +227,21 @@ in {
warnings =
mapAttrsToList (pool: poolOpts: ''
- Using config.services.phpfpm.pools.${pool}.listen is deprecated and will become unsupported. Please reference the read-only option config.services.phpfpm.pools.${pool}.socket to access the path of your socket.
- '') (filterAttrs (pool: poolOpts: poolOpts.listen != "") cfg.pools)
+ Using config.services.phpfpm.pools.${pool}.listen is deprecated and will become unsupported in a future release. Please reference the read-only option config.services.phpfpm.pools.${pool}.socket to access the path of your socket.
+ '') (filterAttrs (pool: poolOpts: poolOpts.listen != "") cfg.pools) ++
+ mapAttrsToList (pool: poolOpts: ''
+ Using config.services.phpfpm.pools.${pool}.extraConfig is deprecated and will become unsupported in a future release. Please migrate your configuration to config.services.phpfpm.pools.${pool}.settings.
+ '') (filterAttrs (pool: poolOpts: poolOpts.extraConfig != null) cfg.pools) ++
+ optional (cfg.extraConfig != null) ''
+ Using config.services.phpfpm.extraConfig is deprecated and will become unsupported in a future release. Please migrate your configuration to config.services.phpfpm.settings.
+ ''
;
+ services.phpfpm.settings = {
+ error_log = "syslog";
+ daemonize = false;
+ };
+
systemd.slices.phpfpm = {
description = "PHP FastCGI Process manager pools slice";
};