Skip to content

Commit

Permalink
nixos/phpfpm: add socket option to replace the listen option
Browse files Browse the repository at this point in the history
  • Loading branch information
aanderse committed Aug 23, 2019
1 parent 2b5f663 commit 62b774a
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 22 deletions.
6 changes: 2 additions & 4 deletions nixos/modules/services/misc/zoneminder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

let
cfg = config.services.zoneminder;
fpm = config.services.phpfpm.pools.zoneminder;
pkg = pkgs.zoneminder;

dirName = pkg.dirName;
Expand All @@ -19,8 +20,6 @@ let

useCustomDir = cfg.storageDir != null;

socket = "/run/phpfpm/${dirName}.sock";

zms = "/cgi-bin/zms";

dirs = dirList: [ dirName ] ++ map (e: "${dirName}/${e}") dirList;
Expand Down Expand Up @@ -274,7 +273,7 @@ in {
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:${socket};
fastcgi_pass unix:${fpm.socket};
}
}
'';
Expand All @@ -284,7 +283,6 @@ in {

phpfpm = lib.mkIf useNginx {
pools.zoneminder = {
listen = socket;
phpOptions = ''
date.timezone = "${config.time.timeZone}"
Expand Down
5 changes: 2 additions & 3 deletions nixos/modules/services/web-apps/icingaweb2/icingaweb2.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }: with lib; let
cfg = config.services.icingaweb2;
fpm = config.services.phpfpm.pools.${poolName};
poolName = "icingaweb2";
phpfpmSocketName = "/var/run/phpfpm/${poolName}.sock";

defaultConfig = {
global = {
Expand Down Expand Up @@ -166,7 +166,6 @@ in {
config = mkIf cfg.enable {
services.phpfpm.pools = mkIf (cfg.pool == "${poolName}") {
"${poolName}" = {
listen = phpfpmSocketName;
extraConfig = ''
listen.owner = nginx
listen.group = nginx
Expand Down Expand Up @@ -210,7 +209,7 @@ in {
include ${config.services.nginx.package}/conf/fastcgi.conf;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:${phpfpmSocketName};
fastcgi_pass unix:${fpm.socket};
fastcgi_param SCRIPT_FILENAME ${pkgs.icingaweb2}/public/index.php;
'';
};
Expand Down
3 changes: 1 addition & 2 deletions nixos/modules/services/web-apps/limesurvey.nix
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ in
};

services.phpfpm.pools.limesurvey = {
listen = "/run/phpfpm/limesurvey.sock";
extraConfig = ''
listen.owner = ${config.services.httpd.user};
listen.group = ${config.services.httpd.group};
Expand Down Expand Up @@ -241,7 +240,7 @@ in
<Directory "${pkg}/share/limesurvey">
<FilesMatch "\.php$">
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:unix:${fpm.listen}|fcgi://localhost/"
SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
</If>
</FilesMatch>
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/web-apps/mediawiki.nix
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ in
<Directory "${pkg}/share/mediawiki">
<FilesMatch "\.php$">
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:unix:${fpm.listen}|fcgi://localhost/"
SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
</If>
</FilesMatch>
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/services/web-apps/nextcloud.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ with lib;

let
cfg = config.services.nextcloud;
fpm = config.services.phpfpm.pools.nextcloud;

phpPackage = pkgs.php73;
phpPackages = pkgs.php73Packages;
Expand Down Expand Up @@ -418,7 +419,6 @@ in {
in {
phpOptions = phpOptionsExtensions;
phpPackage = phpPackage;
listen = "/run/phpfpm/nextcloud";
extraConfig = ''
listen.owner = nginx
listen.group = nginx
Expand Down Expand Up @@ -489,7 +489,7 @@ in {
fastcgi_param HTTPS ${if cfg.https then "on" else "off"};
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass unix:/run/phpfpm/nextcloud;
fastcgi_pass unix:${fpm.socket};
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
fastcgi_read_timeout 120s;
Expand Down
5 changes: 2 additions & 3 deletions nixos/modules/services/web-apps/restya-board.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ with lib;

let
cfg = config.services.restya-board;
fpm = config.services.phpfpm.pools.${poolName};

runDir = "/run/restya-board";

poolName = "restya-board";
phpfpmSocketName = "/run/phpfpm/${poolName}.sock";

in

Expand Down Expand Up @@ -180,7 +180,6 @@ in

services.phpfpm.pools = {
"${poolName}" = {
listen = phpfpmSocketName;
phpOptions = ''
date.timezone = "CET"
Expand Down Expand Up @@ -241,7 +240,7 @@ in
tryFiles = "$uri =404";
extraConfig = ''
include ${pkgs.nginx}/conf/fastcgi_params;
fastcgi_pass unix:${phpfpmSocketName};
fastcgi_pass unix:${fpm.socket};
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "upload_max_filesize=9G \n post_max_size=9G \n max_execution_time=200 \n max_input_time=200 \n memory_limit=256M";
Expand Down
2 changes: 0 additions & 2 deletions nixos/modules/services/web-apps/selfoss.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ let
cfg = config.services.selfoss;

poolName = "selfoss_pool";
phpfpmSocketName = "/run/phpfpm/${poolName}.sock";

dataDir = "/var/lib/selfoss";

Expand Down Expand Up @@ -118,7 +117,6 @@ in

services.phpfpm.pools = mkIf (cfg.pool == "${poolName}") {
"${poolName}" = {
listen = phpfpmSocketName;
extraConfig = ''
listen.owner = nginx
listen.group = nginx
Expand Down
3 changes: 1 addition & 2 deletions nixos/modules/services/web-apps/tt-rss.nix
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ let

services.phpfpm.pools = mkIf (cfg.pool == "${poolName}") {
"${poolName}" = {
listen = "/var/run/phpfpm/${poolName}.sock";
extraConfig = ''
listen.owner = nginx
listen.group = nginx
Expand Down Expand Up @@ -552,7 +551,7 @@ let
locations."~ \.php$" = {
extraConfig = ''
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:${config.services.phpfpm.pools.${cfg.pool}.listen};
fastcgi_pass unix:${config.services.phpfpm.pools.${cfg.pool}.socket};
fastcgi_index index.php;
'';
};
Expand Down
28 changes: 25 additions & 3 deletions nixos/modules/services/web-servers/phpfpm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let
${cfg.extraConfig}
[${pool}]
listen = ${poolOpts.listen}
listen = ${poolOpts.socket}
${poolOpts.extraConfig}
'';

Expand All @@ -29,11 +29,24 @@ let
cat $phpPackage/etc/php.ini $nixDefaultsPath $phpOptionsPath > $out
'';

poolOpts = { lib, ... }:
poolOpts = { lib, name, ... }:
let
poolOpts = cfg.pools."${name}";
in
{
options = {
socket = mkOption {
type = types.str;
readOnly = true;
description = ''
Path to the unix socket file on which to accept FastCGI requests.
<note><para>This option is read-only and managed by NixOS.</para></note>
'';
};

listen = mkOption {
type = types.str;
default = "";
example = "/path/to/unix/socket";
description = ''
The address on which to accept FastCGI requests.
Expand Down Expand Up @@ -77,6 +90,10 @@ let
'';
};
};

config = {
socket = if poolOpts.listen == "" then "${stateDir}/${name}.sock" else poolOpts.listen;
};
};

in {
Expand Down Expand Up @@ -121,7 +138,6 @@ in {
example = literalExample ''
{
mypool = {
listen = "/path/to/unix/socket";
phpPackage = pkgs.php;
extraConfig = '''
user = nobody
Expand All @@ -144,6 +160,12 @@ in {

config = mkIf (cfg.pools != {}) {

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)
;

systemd.slices.phpfpm = {
description = "PHP FastCGI Process manager pools slice";
};
Expand Down

0 comments on commit 62b774a

Please sign in to comment.