aboutsummaryrefslogtreecommitdiff
path: root/nixops
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-21 02:47:52 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-21 02:47:52 +0200
commitf40f5b235b890f46770a22f005f8a0f664cf0562 (patch)
tree60bbcac4b528324fe7e83f280d65190b57bb810a /nixops
parent1480d60775dcd38b33abd367a91cd1b865aacc54 (diff)
downloadNix-f40f5b235b890f46770a22f005f8a0f664cf0562.tar.gz
Nix-f40f5b235b890f46770a22f005f8a0f664cf0562.tar.zst
Nix-f40f5b235b890f46770a22f005f8a0f664cf0562.zip
Replace myPhpfpm with correct overrides
Diffstat (limited to 'nixops')
-rw-r--r--nixops/modules/task/default.nix2
-rw-r--r--nixops/modules/websites/default.nix4
-rw-r--r--nixops/modules/websites/phpfpm/default.nix217
-rw-r--r--nixops/modules/websites/phpfpm/pool-options.nix35
-rw-r--r--nixops/modules/websites/tools/cloud.nix8
-rw-r--r--nixops/modules/websites/tools/dav/default.nix2
-rw-r--r--nixops/modules/websites/tools/git/default.nix2
-rw-r--r--nixops/modules/websites/tools/tools/default.nix140
-rw-r--r--nixops/modules/websites/tools/tools/roundcubemail.nix1
9 files changed, 92 insertions, 319 deletions
diff --git a/nixops/modules/task/default.nix b/nixops/modules/task/default.nix
index e1c933f..e620318 100644
--- a/nixops/modules/task/default.nix
+++ b/nixops/modules/task/default.nix
@@ -160,7 +160,7 @@ in {
160 </Location> 160 </Location>
161 '') env.taskwarrior-web); 161 '') env.taskwarrior-web);
162 }; 162 };
163 services.myPhpfpm.poolConfigs = { 163 services.phpfpm.poolConfigs = {
164 tasks = '' 164 tasks = ''
165 listen = /var/run/phpfpm/task.sock 165 listen = /var/run/phpfpm/task.sock
166 user = ${user} 166 user = ${user}
diff --git a/nixops/modules/websites/default.nix b/nixops/modules/websites/default.nix
index 584892a..1948fe9 100644
--- a/nixops/modules/websites/default.nix
+++ b/nixops/modules/websites/default.nix
@@ -76,8 +76,6 @@ in
76 ./tools/diaspora.nix 76 ./tools/diaspora.nix
77 ./tools/ether.nix 77 ./tools/ether.nix
78 ./tools/peertube.nix 78 ./tools/peertube.nix
79 # Adapted from base phpfpm
80 ./phpfpm
81 ]; 79 ];
82 80
83 config = { 81 config = {
@@ -156,7 +154,7 @@ in
156 ln -s ${adminer.webRoot} $out/webapps/${adminer.apache.webappName} 154 ln -s ${adminer.webRoot} $out/webapps/${adminer.apache.webappName}
157 ''; 155 '';
158 156
159 services.myPhpfpm = { 157 services.phpfpm = {
160 phpPackage = pkgs.php; 158 phpPackage = pkgs.php;
161 phpOptions = '' 159 phpOptions = ''
162 session.save_path = "/var/lib/php/sessions" 160 session.save_path = "/var/lib/php/sessions"
diff --git a/nixops/modules/websites/phpfpm/default.nix b/nixops/modules/websites/phpfpm/default.nix
deleted file mode 100644
index 60959e0..0000000
--- a/nixops/modules/websites/phpfpm/default.nix
+++ /dev/null
@@ -1,217 +0,0 @@
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.myPhpfpm;
7 enabled = cfg.poolConfigs != {} || cfg.pools != {};
8
9 stateDir = "/run/phpfpm";
10
11 poolConfigs = cfg.poolConfigs // mapAttrs mkPool cfg.pools;
12
13 mkPool = n: p: ''
14 listen = ${p.listen}
15 ${p.extraConfig}
16 '';
17
18 fpmCfgFile = pool: poolConfig: pkgs.writeText "phpfpm-${pool}.conf" ''
19 [global]
20 error_log = syslog
21 daemonize = no
22 ${cfg.extraConfig}
23
24 [${pool}]
25 ${poolConfig}
26 '';
27
28 phpIni = poolPhpOptions: (pkgs.runCommand "php.ini" {
29 inherit (cfg) phpPackage phpOptions;
30 inherit poolPhpOptions;
31 nixDefaults = ''
32 sendmail_path = "/run/wrappers/bin/sendmail -t -i"
33 '';
34 passAsFile = [ "nixDefaults" "phpOptions" "poolPhpOptions" ];
35 } ''
36 cat $phpPackage/etc/php.ini $nixDefaultsPath $phpOptionsPath $poolPhpOptionsPath > $out
37 '');
38
39in {
40
41 options = {
42 services.myPhpfpm = {
43 extraConfig = mkOption {
44 type = types.lines;
45 default = "";
46 description = ''
47 Extra configuration that should be put in the global section of
48 the PHP-FPM configuration file. Do not specify the options
49 <literal>error_log</literal> or
50 <literal>daemonize</literal> here, since they are generated by
51 NixOS.
52 '';
53 };
54
55 phpPackage = mkOption {
56 type = types.package;
57 default = pkgs.php;
58 defaultText = "pkgs.php";
59 description = ''
60 The PHP package to use for running the PHP-FPM service.
61 '';
62 };
63
64 phpOptions = mkOption {
65 type = types.lines;
66 default = "";
67 example =
68 ''
69 date.timezone = "CET"
70 '';
71 description =
72 "Options appended to the PHP configuration file <filename>php.ini</filename>.";
73 };
74
75 serviceDependencies = mkOption {
76 default = {};
77 type = types.attrsOf (types.listOf types.string);
78 example = literalExample ''
79 { mypool = ["postgresql.service"]; }
80 '';
81 description = ''
82 Extra service dependencies specific to pool.
83 '';
84 };
85
86 envFile = mkOption {
87 default = {};
88 type = types.attrsOf types.string;
89 example = literalExample ''
90 { mypool = "path/to/file";
91 }
92 '';
93 description = ''
94 Extra environment file go into the service script.
95 '';
96 };
97
98 preStart = mkOption {
99 default = {};
100 type = types.attrsOf types.lines;
101 example = literalExample ''
102 { mypool = '''
103 touch foo
104 ''';
105 }
106 '';
107 description = ''
108 Extra lines that will go into the preStart systemd service
109 '';
110 };
111
112 poolPhpConfigs = mkOption {
113 default = {};
114 type = types.attrsOf types.lines;
115 example = literalExample ''
116 { mypool = '''
117 extension = some_extension.so
118 ''';
119 }
120 '';
121 description = ''
122 Extra lines that go into the php configuration specific to pool.
123 '';
124 };
125
126 poolConfigs = mkOption {
127 default = {};
128 type = types.attrsOf types.lines;
129 example = literalExample ''
130 { mypool = '''
131 listen = /run/phpfpm/mypool
132 user = nobody
133 pm = dynamic
134 pm.max_children = 75
135 pm.start_servers = 10
136 pm.min_spare_servers = 5
137 pm.max_spare_servers = 20
138 pm.max_requests = 500
139 ''';
140 }
141 '';
142 description = ''
143 A mapping between PHP-FPM pool names and their configurations.
144 See the documentation on <literal>php-fpm.conf</literal> for
145 details on configuration directives. If no pools are defined,
146 the phpfpm service is disabled.
147 '';
148 };
149
150 pools = mkOption {
151 type = types.attrsOf (types.submodule (import ./pool-options.nix {
152 inherit lib;
153 }));
154 default = {};
155 example = literalExample ''
156 {
157 mypool = {
158 listen = "/path/to/unix/socket";
159 extraConfig = '''
160 user = nobody
161 pm = dynamic
162 pm.max_children = 75
163 pm.start_servers = 10
164 pm.min_spare_servers = 5
165 pm.max_spare_servers = 20
166 pm.max_requests = 500
167 ''';
168 }
169 }'';
170 description = ''
171 PHP-FPM pools. If no pools or poolConfigs are defined, the PHP-FPM
172 service is disabled.
173 '';
174 };
175 };
176 };
177
178 config = mkIf enabled {
179
180 systemd.slices.phpfpm = {
181 description = "PHP FastCGI Process manager pools slice";
182 };
183
184 systemd.targets.phpfpm = {
185 description = "PHP FastCGI Process manager pools target";
186 wantedBy = [ "multi-user.target" ];
187 };
188
189 systemd.services = flip mapAttrs' poolConfigs (pool: poolConfig:
190 nameValuePair "phpfpm-${pool}" {
191 description = "PHP FastCGI Process Manager service for pool ${pool}";
192 after = [ "network.target" ] ++ (cfg.serviceDependencies.${pool} or []);
193 wants = cfg.serviceDependencies.${pool} or [];
194 wantedBy = [ "phpfpm.target" ];
195 partOf = [ "phpfpm.target" ];
196 preStart = ''
197 mkdir -p ${stateDir}
198 '' + (cfg.preStart.${pool} or "");
199 serviceConfig = let
200 cfgFile = fpmCfgFile pool poolConfig;
201 poolPhpIni = cfg.poolPhpConfigs.${pool} or "";
202 in {
203 EnvironmentFile = if builtins.hasAttr pool cfg.envFile then [cfg.envFile.${pool}] else [];
204 Slice = "phpfpm.slice";
205 PrivateDevices = true;
206 ProtectSystem = "full";
207 ProtectHome = true;
208 # XXX: We need AF_NETLINK to make the sendmail SUID binary from postfix work
209 RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK";
210 Type = "notify";
211 ExecStart = "${cfg.phpPackage}/bin/php-fpm -y ${cfgFile} -c ${phpIni poolPhpIni}";
212 ExecReload = "${pkgs.coreutils}/bin/kill -USR2 $MAINPID";
213 };
214 }
215 );
216 };
217}
diff --git a/nixops/modules/websites/phpfpm/pool-options.nix b/nixops/modules/websites/phpfpm/pool-options.nix
deleted file mode 100644
index cc688c2..0000000
--- a/nixops/modules/websites/phpfpm/pool-options.nix
+++ /dev/null
@@ -1,35 +0,0 @@
1{ lib }:
2
3with lib; {
4
5 options = {
6
7 listen = mkOption {
8 type = types.str;
9 example = "/path/to/unix/socket";
10 description = ''
11 The address on which to accept FastCGI requests.
12 '';
13 };
14
15 extraConfig = mkOption {
16 type = types.lines;
17 example = ''
18 user = nobody
19 pm = dynamic
20 pm.max_children = 75
21 pm.start_servers = 10
22 pm.min_spare_servers = 5
23 pm.max_spare_servers = 20
24 pm.max_requests = 500
25 '';
26
27 description = ''
28 Extra lines that go into the pool configuration.
29 See the documentation on <literal>php-fpm.conf</literal> for
30 details on configuration directives.
31 '';
32 };
33 };
34}
35
diff --git a/nixops/modules/websites/tools/cloud.nix b/nixops/modules/websites/tools/cloud.nix
index 5e010f4..5d2ca40 100644
--- a/nixops/modules/websites/tools/cloud.nix
+++ b/nixops/modules/websites/tools/cloud.nix
@@ -17,7 +17,6 @@ let
17 zend_extension=${pkgs.php}/lib/php/extensions/opcache.so 17 zend_extension=${pkgs.php}/lib/php/extensions/opcache.so
18 ''; 18 '';
19 pool = '' 19 pool = ''
20 listen = ${socket}
21 user = wwwrun 20 user = wwwrun
22 group = wwwrun 21 group = wwwrun
23 listen.owner = wwwrun 22 listen.owner = wwwrun
@@ -170,9 +169,10 @@ in {
170 ln -s ${nextcloud} $out/webapps/${webappName} 169 ln -s ${nextcloud} $out/webapps/${webappName}
171 ''; 170 '';
172 171
173 services.myPhpfpm = { 172 services.phpfpm.pools.nextcloud = {
174 poolPhpConfigs.nextcloud = phpFpm.phpConfig; 173 listen = phpFpm.socket;
175 poolConfigs.nextcloud = phpFpm.pool; 174 extraConfig = phpFpm.pool;
175 phpOptions = config.services.phpfpm.phpOptions + phpFpm.phpConfig;
176 }; 176 };
177 177
178 services.cron = { 178 services.cron = {
diff --git a/nixops/modules/websites/tools/dav/default.nix b/nixops/modules/websites/tools/dav/default.nix
index 075cf48..78e0ba3 100644
--- a/nixops/modules/websites/tools/dav/default.nix
+++ b/nixops/modules/websites/tools/dav/default.nix
@@ -41,7 +41,7 @@ in {
41 ]; 41 ];
42 }; 42 };
43 43
44 services.myPhpfpm.poolConfigs = { 44 services.phpfpm.poolConfigs = {
45 davical = davical.phpFpm.pool; 45 davical = davical.phpFpm.pool;
46 }; 46 };
47 47
diff --git a/nixops/modules/websites/tools/git/default.nix b/nixops/modules/websites/tools/git/default.nix
index 064d3dd..495c5ea 100644
--- a/nixops/modules/websites/tools/git/default.nix
+++ b/nixops/modules/websites/tools/git/default.nix
@@ -38,7 +38,7 @@ in {
38 '' 38 ''
39 ]; 39 ];
40 }; 40 };
41 services.myPhpfpm.poolConfigs = { 41 services.phpfpm.poolConfigs = {
42 mantisbt = mantisbt.phpFpm.pool; 42 mantisbt = mantisbt.phpFpm.pool;
43 }; 43 };
44 }; 44 };
diff --git a/nixops/modules/websites/tools/tools/default.nix b/nixops/modules/websites/tools/tools/default.nix
index 061c004..642755f 100644
--- a/nixops/modules/websites/tools/tools/default.nix
+++ b/nixops/modules/websites/tools/tools/default.nix
@@ -72,15 +72,6 @@ in {
72 ++ ldap.apache.modules 72 ++ ldap.apache.modules
73 ++ kanboard.apache.modules; 73 ++ kanboard.apache.modules;
74 74
75 systemd.services.ympd = {
76 description = "Standalone MPD Web GUI written in C";
77 wantedBy = [ "multi-user.target" ];
78 script = ''
79 export MPD_PASSWORD=$(cat /var/secrets/mpd)
80 ${pkgs.ympd}/bin/ympd --host ${ympd.config.host} --port ${toString ympd.config.port} --webport ${ympd.config.webPort} --user nobody
81 '';
82 };
83
84 services.websites.integration.vhostConfs.devtools = { 75 services.websites.integration.vhostConfs.devtools = {
85 certName = "eldiron"; 76 certName = "eldiron";
86 addToCerts = true; 77 addToCerts = true;
@@ -157,33 +148,99 @@ in {
157 ]; 148 ];
158 }; 149 };
159 150
160 services.myPhpfpm.serviceDependencies = { 151 systemd.services = {
161 dokuwiki = dokuwiki.phpFpm.serviceDeps; 152 phpfpm-dokuwiki = {
162 kanboard = kanboard.phpFpm.serviceDeps; 153 after = lib.mkAfter dokuwiki.phpFpm.serviceDeps;
163 ldap = ldap.phpFpm.serviceDeps; 154 wants = dokuwiki.phpFpm.serviceDeps;
164 rainloop = rainloop.phpFpm.serviceDeps; 155 };
165 roundcubemail = roundcubemail.phpFpm.serviceDeps; 156 phpfpm-kanboard = {
166 shaarli = shaarli.phpFpm.serviceDeps; 157 after = lib.mkAfter kanboard.phpFpm.serviceDeps;
167 ttrss = ttrss.phpFpm.serviceDeps; 158 wants = kanboard.phpFpm.serviceDeps;
168 wallabag = wallabag.phpFpm.serviceDeps; 159 };
169 yourls = yourls.phpFpm.serviceDeps; 160 phpfpm-ldap = {
161 after = lib.mkAfter ldap.phpFpm.serviceDeps;
162 wants = ldap.phpFpm.serviceDeps;
163 };
164 phpfpm-rainloop = {
165 after = lib.mkAfter rainloop.phpFpm.serviceDeps;
166 wants = rainloop.phpFpm.serviceDeps;
167 };
168 phpfpm-roundcubemail = {
169 after = lib.mkAfter roundcubemail.phpFpm.serviceDeps;
170 wants = roundcubemail.phpFpm.serviceDeps;
171 };
172 phpfpm-shaarli = {
173 after = lib.mkAfter shaarli.phpFpm.serviceDeps;
174 wants = shaarli.phpFpm.serviceDeps;
175 };
176 phpfpm-ttrss = {
177 after = lib.mkAfter ttrss.phpFpm.serviceDeps;
178 wants = ttrss.phpFpm.serviceDeps;
179 };
180 phpfpm-wallabag = {
181 after = lib.mkAfter wallabag.phpFpm.serviceDeps;
182 wants = wallabag.phpFpm.serviceDeps;
183 preStart = lib.mkAfter wallabag.phpFpm.preStart;
184 };
185 phpfpm-yourls = {
186 after = lib.mkAfter yourls.phpFpm.serviceDeps;
187 wants = yourls.phpFpm.serviceDeps;
188 };
189 ympd = {
190 description = "Standalone MPD Web GUI written in C";
191 wantedBy = [ "multi-user.target" ];
192 script = ''
193 export MPD_PASSWORD=$(cat /var/secrets/mpd)
194 ${pkgs.ympd}/bin/ympd --host ${ympd.config.host} --port ${toString ympd.config.port} --webport ${ympd.config.webPort} --user nobody
195 '';
196 };
197 tt-rss = {
198 description = "Tiny Tiny RSS feeds update daemon";
199 serviceConfig = {
200 User = "wwwrun";
201 ExecStart = "${pkgs.php}/bin/php ${ttrss.webRoot}/update.php --daemon";
202 StandardOutput = "syslog";
203 StandardError = "syslog";
204 PermissionsStartOnly = true;
205 };
206
207 wantedBy = [ "multi-user.target" ];
208 requires = ["postgresql.service"];
209 after = ["network.target" "postgresql.service"];
210 };
211 };
212
213 services.phpfpm.pools.roundcubemail = {
214 listen = roundcubemail.phpFpm.socket;
215 extraConfig = roundcubemail.phpFpm.pool;
216 phpOptions = config.services.phpfpm.phpOptions + roundcubemail.phpFpm.phpConfig;
170 }; 217 };
171 218
172 services.myPhpfpm.poolPhpConfigs = { 219 services.phpfpm.pools.devtools = {
173 devtools = '' 220 listen = "/var/run/phpfpm/devtools.sock";
221 extraConfig = ''
222 user = wwwrun
223 group = wwwrun
224 listen.owner = wwwrun
225 listen.group = wwwrun
226 pm = dynamic
227 pm.max_children = 60
228 pm.start_servers = 2
229 pm.min_spare_servers = 1
230 pm.max_spare_servers = 10
231
232 php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:/var/lib/ftp/devtools.immae.eu:/tmp"
233 '';
234 phpOptions = config.services.phpfpm.phpOptions + ''
174 extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so 235 extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so
175 extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so 236 extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so
176 zend_extension=${pkgs.php}/lib/php/extensions/opcache.so 237 zend_extension=${pkgs.php}/lib/php/extensions/opcache.so
177 ''; 238 '';
178 roundcubemail = roundcubemail.phpFpm.phpConfig;
179 };
180 services.myPhpfpm.preStart = {
181 wallabag = wallabag.phpFpm.preStart;
182 }; 239 };
183 services.myPhpfpm.poolConfigs = { 240
241 services.phpfpm.poolConfigs = {
184 adminer = adminer.phpFpm.pool; 242 adminer = adminer.phpFpm.pool;
185 ttrss = ttrss.phpFpm.pool; 243 ttrss = ttrss.phpFpm.pool;
186 roundcubemail = roundcubemail.phpFpm.pool;
187 wallabag = wallabag.phpFpm.pool; 244 wallabag = wallabag.phpFpm.pool;
188 yourls = yourls.phpFpm.pool; 245 yourls = yourls.phpFpm.pool;
189 rompr = rompr.phpFpm.pool; 246 rompr = rompr.phpFpm.pool;
@@ -192,20 +249,6 @@ in {
192 ldap = ldap.phpFpm.pool; 249 ldap = ldap.phpFpm.pool;
193 rainloop = rainloop.phpFpm.pool; 250 rainloop = rainloop.phpFpm.pool;
194 kanboard = kanboard.phpFpm.pool; 251 kanboard = kanboard.phpFpm.pool;
195 devtools = ''
196 listen = /var/run/phpfpm/devtools.sock
197 user = wwwrun
198 group = wwwrun
199 listen.owner = wwwrun
200 listen.group = wwwrun
201 pm = dynamic
202 pm.max_children = 60
203 pm.start_servers = 2
204 pm.min_spare_servers = 1
205 pm.max_spare_servers = 10
206
207 php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:/var/lib/ftp/devtools.immae.eu:/tmp"
208 '';
209 tools = '' 252 tools = ''
210 listen = /var/run/phpfpm/tools.sock 253 listen = /var/run/phpfpm/tools.sock
211 user = wwwrun 254 user = wwwrun
@@ -250,21 +293,6 @@ in {
250 ln -s ${kanboard.webRoot} $out/webapps/${kanboard.apache.webappName} 293 ln -s ${kanboard.webRoot} $out/webapps/${kanboard.apache.webappName}
251 ''; 294 '';
252 295
253 systemd.services.tt-rss = {
254 description = "Tiny Tiny RSS feeds update daemon";
255 serviceConfig = {
256 User = "wwwrun";
257 ExecStart = "${pkgs.php}/bin/php ${ttrss.webRoot}/update.php --daemon";
258 StandardOutput = "syslog";
259 StandardError = "syslog";
260 PermissionsStartOnly = true;
261 };
262
263 wantedBy = [ "multi-user.target" ];
264 requires = ["postgresql.service"];
265 after = ["network.target" "postgresql.service"];
266 };
267
268 }; 296 };
269} 297}
270 298
diff --git a/nixops/modules/websites/tools/tools/roundcubemail.nix b/nixops/modules/websites/tools/tools/roundcubemail.nix
index 6177ff3..8974d1b 100644
--- a/nixops/modules/websites/tools/tools/roundcubemail.nix
+++ b/nixops/modules/websites/tools/tools/roundcubemail.nix
@@ -102,7 +102,6 @@ rec {
102 ''; 102 '';
103 socket = "/var/run/phpfpm/roundcubemail.sock"; 103 socket = "/var/run/phpfpm/roundcubemail.sock";
104 pool = '' 104 pool = ''
105 listen = ${socket}
106 user = ${apache.user} 105 user = ${apache.user}
107 group = ${apache.group} 106 group = ${apache.group}
108 listen.owner = ${apache.user} 107 listen.owner = ${apache.user}