]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - virtual/eldiron.nix
Add roundcubemail
[perso/Immae/Config/Nix.git] / virtual / eldiron.nix
1 {
2 network = {
3 description = "Immae's network";
4 enableRollback = true;
5 };
6
7 eldiron = { config, pkgs, ... }:
8 with import ../libs.nix;
9 let
10 mypkgs = pkgs.callPackage ./packages.nix {
11 inherit checkEnv fetchedGit fetchedGitPrivate fetchedGithub;
12 };
13 in
14 {
15 nixpkgs.config.packageOverrides = oldpkgs: rec {
16 gitolite = oldpkgs.gitolite.overrideAttrs(old: rec {
17 name = "gitolite-${version}";
18 version = "3.6.10";
19 src = pkgs.fetchFromGitHub {
20 owner = "sitaramc";
21 repo = "gitolite";
22 rev = "v${version}";
23 sha256 = "0p2697mn6rwm03ndlv7q137zczai82n41aplq1g006ii7f12xy8h";
24 };
25 });
26 gitweb = oldpkgs.gitweb.overrideAttrs(old: {
27 installPhase = old.installPhase + ''
28 cp -r ${./packages/gitweb} $out/gitweb-theme;
29 '';
30 });
31 postgresql = postgresql111;
32 postgresql111 = oldpkgs.postgresql100.overrideAttrs(old: rec {
33 passthru = old.passthru // { psqlSchema = "11.0"; };
34 name = "postgresql-11.1";
35 src = pkgs.fetchurl {
36 url = "mirror://postgresql/source/v11.1/${name}.tar.bz2";
37 sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch";
38 };
39 });
40 mariadb = mariadbPAM;
41 mariadbPAM = oldpkgs.mariadb.overrideAttrs(old: rec {
42 cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ];
43 buildInputs = old.buildInputs ++ [ pkgs.pam ];
44 });
45 goaccess = oldpkgs.goaccess.overrideAttrs(old: rec {
46 name = "goaccess-${version}";
47 version = "1.3";
48 src = pkgs.fetchurl {
49 url = "https://tar.goaccess.io/${name}.tar.gz";
50 sha256 = "16vv3pj7pbraq173wlxa89jjsd279004j4kgzlrsk1dz4if5qxwc";
51 };
52 configureFlags = old.configureFlags ++ [ "--enable-tcb=btree" ];
53 buildInputs = old.buildInputs ++ [ pkgs.tokyocabinet pkgs.bzip2 ];
54 });
55 };
56
57 networking = {
58 firewall = {
59 enable = true;
60 allowedTCPPorts = [ 22 80 443 3306 5432 9418 ];
61 };
62 };
63
64 deployment = {
65 targetEnv = "hetzner";
66 hetzner = {
67 #robotUser = "defined in HETZNER_ROBOT_USER";
68 #robotPass = "defined in HETZNER_ROBOT_PASS";
69 mainIPv4 = "176.9.151.89";
70 partitions = ''
71 clearpart --all --initlabel --drives=sda,sdb
72
73 part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
74 part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb
75
76 part raid.1 --grow --ondisk=sda
77 part raid.2 --grow --ondisk=sdb
78
79 raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2
80 '';
81 };
82 };
83
84 environment.systemPackages = let
85 # FIXME: move it to nextcloud
86 occ = pkgs.writeScriptBin "nextcloud-occ" ''
87 #! ${pkgs.stdenv.shell}
88 cd ${mypkgs.nextcloud.webRoot}
89 NEXTCLOUD_CONFIG_DIR="${mypkgs.nextcloud.webRoot}/config" \
90 exec \
91 ${config.services.phpfpm.phpPackage}/bin/php \
92 -c ${config.services.phpfpm.phpPackage}/etc/php.ini \
93 occ $*
94 '';
95 in [
96 pkgs.telnet
97 pkgs.htop
98 pkgs.vim
99 pkgs.goaccess
100 occ
101 ];
102
103 # FIXME: doesn't work with httpd?
104 security.acme.preliminarySelfsigned = true;
105 security.acme.certs = {
106 # FIXME: /!\ To create a new certificate, create it before using
107 # it in httpd
108 "eldiron" = {
109 webroot = "/var/lib/acme/acme-challenge";
110 email = "ismael@bouya.org";
111 domain = "eldiron.immae.eu";
112 plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
113 postRun = ''
114 systemctl reload httpd.service
115 '';
116 allowKeysForGroup = true;
117 extraDomains = {
118 "db-1.immae.eu" = null;
119 "git.immae.eu" = null;
120 "tools.immae.eu" = null;
121 "connexionswing.immae.eu" = null;
122 "sandetludo.immae.eu" = null;
123 "cloud.immae.eu" = null;
124 "ludivine.immae.eu" = null;
125 "dev.aten.pro" = null;
126 "piedsjaloux.immae.eu" = null;
127 "chloe.immae.eu" = null;
128 };
129 };
130 "ludivinecassal" = {
131 webroot = "/var/lib/acme/acme-challenge";
132 email = "ismael@bouya.org";
133 domain = "ludivinecassal.com";
134 plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
135 postRun = ''
136 systemctl reload httpd.service
137 '';
138 extraDomains = {
139 "www.ludivinecassal.com" = null;
140 };
141 };
142 "aten" = {
143 webroot = "/var/lib/acme/acme-challenge";
144 email = "ismael@bouya.org";
145 domain = "aten.pro";
146 plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
147 postRun = ''
148 systemctl reload httpd.service
149 '';
150 extraDomains = {
151 "www.aten.pro" = null;
152 };
153 };
154 "piedsjaloux" = {
155 webroot = "/var/lib/acme/acme-challenge";
156 email = "ismael@bouya.org";
157 domain = "piedsjaloux.fr";
158 plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
159 postRun = ''
160 systemctl reload httpd.service
161 '';
162 extraDomains = {
163 "www.piedsjaloux.fr" = null;
164 };
165 };
166 "chloe" = {
167 webroot = "/var/lib/acme/acme-challenge";
168 email = "ismael@bouya.org";
169 domain = "osteopathe-cc.fr";
170 plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
171 postRun = ''
172 systemctl reload httpd.service
173 '';
174 extraDomains = {
175 "www.osteopathe-cc.fr" = null;
176 };
177 };
178 # "connexionswing" = {
179 # webroot = "/var/lib/acme/acme-challenge";
180 # email = "ismael@bouya.org";
181 # domain = "connexionswing.com";
182 # plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
183 # postRun = ''
184 # systemctl reload httpd.service
185 # '';
186 # extraDomains = {
187 # "www.connexionswing.com" = null;
188 # "sandetludo.com" = null;
189 # "www.sandetludo.com" = null;
190 # };
191 # };
192 };
193
194 services.openssh.extraConfig = ''
195 AuthorizedKeysCommand /etc/ssh/ldap_authorized_keys
196 AuthorizedKeysCommandUser nobody
197 '';
198
199 users.users.wwwrun.extraGroups = [ "gitolite" ];
200
201 users.users.gitolite.packages = let
202 python-packages = python-packages: with python-packages; [
203 simplejson
204 urllib3
205 ];
206 in
207 [
208 (pkgs.python3.withPackages python-packages)
209 ];
210 # FIXME: after initial install, need to
211 # (1) copy rc file (adjust gitolite_ldap_groups.sh)
212 # (2) (mark old readonly and) sync repos except gitolite-admin
213 # rsync -av --exclude=gitolite-admin.git old:/var/lib/gitolite/repositories /var/lib/gitolite/
214 # chown -R gitolite:gitolite /var/lib/gitolite
215 # (3) push force the gitolite-admin to new location (from external point)
216 # Don't use an existing key, it will take precedence over
217 # gitolite-admin
218 # (4) su -u gitolite gitolite setup
219 services.gitolite = {
220 enable = true;
221 # FIXME: key from ./ssh
222 adminPubkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXqRbiHw7QoHADNIEuo4nUT9fSOIEBMdJZH0bkQAxXyJFyCM1IMz0pxsHV0wu9tdkkr36bPEUj2aV5bkYLBN6nxcV2Y49X8bjOSCPfx3n6Own1h+NeZVBj4ZByrFmqCbTxUJIZ2bZKcWOFncML39VmWdsVhNjg0X4NBBehqXRIKr2gt3E/ESAxTYJFm0BnU0baciw9cN0bsRGqvFgf5h2P48CIAfwhVcGmPQnnAwabnosYQzRWxR0OygH5Kd8mePh6FheIRIigfXsDO8f/jdxwut8buvNIf3m5EBr3tUbTsvM+eV3M5vKGt7sk8T64DVtepTSdOOWtp+47ktsnHOMh immae@immae.eu";
223 };
224
225 services.ympd = mypkgs.ympd.config // { enable = false; };
226
227 services.phpfpm = {
228 # FIXME: move session files to separate dirs
229 # /!\ phppackage is used in nextcloud configuation
230 phpOptions = ''
231 session.save_path = "/var/lib/php/sessions"
232 session.gc_maxlifetime = 60*60*24*15
233 session.cache_expire = 60*24*30
234 ; For nextcloud
235 extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so
236 ; For nextcloud
237 extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so
238 ; For nextcloud
239 zend_extension=${pkgs.php}/lib/php/extensions/opcache.so
240 '';
241 extraConfig = ''
242 log_level = notice
243 '';
244 poolConfigs = {
245 adminer = mypkgs.adminer.phpFpm.pool;
246 connexionswing_dev = mypkgs.connexionswing_dev.phpFpm.pool;
247 connexionswing_prod = mypkgs.connexionswing_prod.phpFpm.pool;
248 ludivinecassal_dev = mypkgs.ludivinecassal_dev.phpFpm.pool;
249 ludivinecassal_prod = mypkgs.ludivinecassal_prod.phpFpm.pool;
250 piedsjaloux_dev = mypkgs.piedsjaloux_dev.phpFpm.pool;
251 piedsjaloux_prod = mypkgs.piedsjaloux_prod.phpFpm.pool;
252 chloe_dev = mypkgs.chloe_dev.phpFpm.pool;
253 chloe_prod = mypkgs.chloe_prod.phpFpm.pool;
254 aten_dev = mypkgs.aten_dev.phpFpm.pool;
255 aten_prod = mypkgs.aten_prod.phpFpm.pool;
256 nextcloud = mypkgs.nextcloud.phpFpm.pool;
257 mantisbt = mypkgs.mantisbt.phpFpm.pool;
258 ttrss = mypkgs.ttrss.phpFpm.pool;
259 roundcubemail = mypkgs.roundcubemail.phpFpm.pool;
260 };
261 };
262
263 system.activationScripts = {
264 connexionswing_dev = mypkgs.connexionswing_dev.activationScript;
265 connexionswing_prod = mypkgs.connexionswing_prod.activationScript;
266 ludivinecassal_dev = mypkgs.ludivinecassal_dev.activationScript;
267 ludivinecassal_prod = mypkgs.ludivinecassal_prod.activationScript;
268 piedsjaloux_dev = mypkgs.piedsjaloux_dev.activationScript;
269 piedsjaloux_prod = mypkgs.piedsjaloux_prod.activationScript;
270 chloe_dev = mypkgs.chloe_dev.activationScript;
271 chloe_prod = mypkgs.chloe_prod.activationScript;
272 aten_dev = mypkgs.aten_dev.activationScript;
273 aten_prod = mypkgs.aten_prod.activationScript;
274 nextcloud = mypkgs.nextcloud.activationScript;
275 ttrss = mypkgs.ttrss.activationScript;
276 roundcubemail = mypkgs.roundcubemail.activationScript;
277 httpd = ''
278 install -d -m 0755 /var/lib/acme/acme-challenge
279 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions
280 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/adminer
281 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/mantisbt
282 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/ttrss
283 '';
284 redis = ''
285 mkdir -p /run/redis
286 chown redis /run/redis
287 '';
288 gitolite =
289 assert checkEnv "NIXOPS_GITOLITE_LDAP_PASSWORD";
290 let
291 gitolite_ldap_groups = wrap {
292 name = "gitolite_ldap_groups.sh";
293 file = ./packages/gitolite_ldap_groups.sh;
294 vars = {
295 LDAP_PASS = builtins.getEnv "NIXOPS_GITOLITE_LDAP_PASSWORD";
296 };
297 paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.coreutils ];
298 };
299 in {
300 deps = [ "users" ];
301 text = ''
302 if [ -d /var/lib/gitolite ]; then
303 ln -sf ${gitolite_ldap_groups} /var/lib/gitolite/gitolite_ldap_groups.sh
304 chmod g+rx /var/lib/gitolite
305 fi
306 if [ -f /var/lib/gitolite/projects.list ]; then
307 chmod g+r /var/lib/gitolite/projects.list
308 fi
309 '';
310 };
311 # FIXME: initial sync
312 goaccess = ''
313 mkdir -p /var/lib/goaccess
314 mkdir -p /var/lib/goaccess/aten.pro
315 mkdir -p /var/lib/goaccess/ludivinecassal.com
316 mkdir -p /var/lib/goaccess/piedsjaloux.fr
317 mkdir -p /var/lib/goaccess/osteopathe-cc.fr
318 '';
319 };
320
321 environment.etc."ssh/ldap_authorized_keys" = let
322 ldap_authorized_keys =
323 assert checkEnv "NIXOPS_SSHD_LDAP_PASSWORD";
324 wrap {
325 name = "ldap_authorized_keys";
326 file = ./ldap_authorized_keys.sh;
327 vars = {
328 LDAP_PASS = builtins.getEnv "NIXOPS_SSHD_LDAP_PASSWORD";
329 GITOLITE_SHELL = "${pkgs.gitolite}/bin/gitolite-shell";
330 ECHO = "${pkgs.coreutils}/bin/echo";
331 };
332 paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.gnused pkgs.coreutils ];
333 };
334 in {
335 enable = true;
336 mode = "0755";
337 user = "root";
338 source = ldap_authorized_keys;
339 };
340
341 services.gitDaemon = {
342 enable = true;
343 user = "gitolite";
344 group = "gitolite";
345 basePath = "${mypkgs.git.web.varDir}/repositories";
346 };
347
348 # FIXME: logrotate
349 services.httpd = let
350 withConf = domain: {
351 enableSSL = true;
352 sslServerCert = "/var/lib/acme/${domain}/cert.pem";
353 sslServerKey = "/var/lib/acme/${domain}/key.pem";
354 sslServerChain = "/var/lib/acme/${domain}/fullchain.pem";
355 logFormat = "combinedVhost";
356 listen = [ { ip = "*"; port = 443; } ];
357 };
358 apacheConfig = {
359 gzip = {
360 modules = [ "deflate" "filter" ];
361 extraConfig = ''
362 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
363 '';
364 };
365 ldap = {
366 modules = [ "ldap" "authnz_ldap" ];
367 extraConfig = assert checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; ''
368 <IfModule ldap_module>
369 LDAPSharedCacheSize 500000
370 LDAPCacheEntries 1024
371 LDAPCacheTTL 600
372 LDAPOpCacheEntries 1024
373 LDAPOpCacheTTL 600
374 </IfModule>
375
376 <Macro LDAPConnect>
377 <IfModule authnz_ldap_module>
378 AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu
379 AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu
380 AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}"
381 AuthType Basic
382 AuthName "Authentification requise (Acces LDAP)"
383 AuthBasicProvider ldap
384 </IfModule>
385 </Macro>
386
387 <Macro Stats %{domain}>
388 Alias /awstats /var/lib/goaccess/%{domain}
389 <Directory /var/lib/goaccess/%{domain}>
390 DirectoryIndex index.html
391 AllowOverride None
392 Require all granted
393 </Directory>
394 <Location /awstats>
395 Use LDAPConnect
396 Require ldap-group cn=%{domain},ou=stats,cn=httpd,ou=services,dc=immae,dc=eu
397 </Location>
398 </Macro>
399 '';
400 };
401 http2 = {
402 modules = [ "http2" ];
403 extraConfig = ''
404 Protocols h2 http/1.1
405 '';
406 };
407 customLog = {
408 modules = [];
409 extraConfig = ''
410 LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedVhost
411 '';
412 };
413 };
414 in rec {
415 enable = true;
416 logPerVirtualHost = true;
417 multiProcessingModule = "worker";
418 adminAddr = "httpd@immae.eu";
419 logFormat = "combinedVhost";
420 extraModules = pkgs.lib.lists.unique (
421 mypkgs.adminer.apache.modules ++
422 mypkgs.nextcloud.apache.modules ++
423 mypkgs.connexionswing_dev.apache.modules ++
424 mypkgs.connexionswing_prod.apache.modules ++
425 mypkgs.ludivinecassal_dev.apache.modules ++
426 mypkgs.ludivinecassal_prod.apache.modules ++
427 mypkgs.piedsjaloux_dev.apache.modules ++
428 mypkgs.piedsjaloux_prod.apache.modules ++
429 mypkgs.chloe_dev.apache.modules ++
430 mypkgs.chloe_prod.apache.modules ++
431 mypkgs.aten_dev.apache.modules ++
432 mypkgs.aten_prod.apache.modules ++
433 mypkgs.ympd.apache.modules ++
434 mypkgs.git.web.apache.modules ++
435 mypkgs.mantisbt.apache.modules ++
436 mypkgs.ttrss.apache.modules ++
437 mypkgs.roundcubemail.apache.modules ++
438 pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules) apacheConfig) ++
439 [ "macro" ]);
440 extraConfig = builtins.concatStringsSep "\n"
441 (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig) apacheConfig);
442 virtualHosts = [
443 (withConf "eldiron" // {
444 hostName = "eldiron.immae.eu";
445 documentRoot = ./www;
446 extraConfig = ''
447 DirectoryIndex index.htm
448 '';
449 })
450 (withConf "eldiron" // {
451 hostName = "db-1.immae.eu";
452 documentRoot = null;
453 extraConfig = builtins.concatStringsSep "\n" [
454 mypkgs.adminer.apache.vhostConf
455 ];
456 })
457 (withConf "eldiron" // {
458 hostName = "tools.immae.eu";
459 documentRoot = null;
460 extraConfig = builtins.concatStringsSep "\n" [
461 mypkgs.adminer.apache.vhostConf
462 mypkgs.ympd.apache.vhostConf
463 mypkgs.ttrss.apache.vhostConf
464 mypkgs.roundcubemail.apache.vhostConf
465 ];
466 })
467 (withConf "eldiron" // {
468 hostName = "connexionswing.immae.eu";
469 serverAliases = [ "sandetludo.immae.eu" ];
470 documentRoot = mypkgs.connexionswing_dev.webRoot;
471 extraConfig = builtins.concatStringsSep "\n" [
472 mypkgs.connexionswing_dev.apache.vhostConf
473 ];
474 })
475 (withConf "eldiron" // {
476 hostName = "ludivine.immae.eu";
477 documentRoot = mypkgs.ludivinecassal_dev.webRoot;
478 extraConfig = builtins.concatStringsSep "\n" [
479 mypkgs.ludivinecassal_dev.apache.vhostConf
480 ];
481 })
482 (withConf "ludivinecassal" // {
483 hostName = "ludivinecassal.com";
484 serverAliases = [ "www.ludivinecassal.com" ];
485 documentRoot = mypkgs.ludivinecassal_prod.webRoot;
486 extraConfig = builtins.concatStringsSep "\n" [
487 mypkgs.ludivinecassal_prod.apache.vhostConf
488 ];
489 })
490 (withConf "eldiron" // {
491 hostName = "piedsjaloux.immae.eu";
492 documentRoot = mypkgs.piedsjaloux_dev.webRoot;
493 extraConfig = builtins.concatStringsSep "\n" [
494 mypkgs.piedsjaloux_dev.apache.vhostConf
495 ];
496 })
497 (withConf "piedsjaloux" // {
498 hostName = "piedsjaloux.fr";
499 serverAliases = [ "www.piedsjaloux.fr" ];
500 documentRoot = mypkgs.piedsjaloux_prod.webRoot;
501 extraConfig = builtins.concatStringsSep "\n" [
502 mypkgs.piedsjaloux_prod.apache.vhostConf
503 ];
504 })
505 (withConf "eldiron" // {
506 hostName = "chloe.immae.eu";
507 documentRoot = mypkgs.chloe_dev.webRoot;
508 extraConfig = builtins.concatStringsSep "\n" [
509 mypkgs.chloe_dev.apache.vhostConf
510 ];
511 })
512 (withConf "chloe" // {
513 hostName = "osteopathe-cc.fr";
514 serverAliases = [ "www.osteopathe-cc.fr" ];
515 documentRoot = mypkgs.chloe_prod.webRoot;
516 extraConfig = builtins.concatStringsSep "\n" [
517 mypkgs.chloe_prod.apache.vhostConf
518 ];
519 })
520 (withConf "eldiron" // {
521 hostName = "dev.aten.pro";
522 documentRoot = mypkgs.aten_dev.webRoot;
523 extraConfig = builtins.concatStringsSep "\n" [
524 mypkgs.aten_dev.apache.vhostConf
525 ];
526 })
527 (withConf "aten" // {
528 hostName = "aten.pro";
529 serverAliases = [ "www.aten.pro" ];
530 documentRoot = mypkgs.aten_prod.webRoot;
531 extraConfig = builtins.concatStringsSep "\n" [
532 mypkgs.aten_prod.apache.vhostConf
533 ];
534 })
535 (withConf "eldiron" // {
536 hostName = "cloud.immae.eu";
537 documentRoot = mypkgs.nextcloud.webRoot;
538 extraConfig = builtins.concatStringsSep "\n" [
539 mypkgs.nextcloud.apache.vhostConf
540 ];
541 })
542 (withConf "eldiron" // {
543 hostName = "git.immae.eu";
544 documentRoot = mypkgs.git.web.webRoot;
545 extraConfig = builtins.concatStringsSep "\n" [
546 mypkgs.git.web.apache.vhostConf
547 mypkgs.mantisbt.apache.vhostConf
548 ] + ''
549 RewriteEngine on
550 RewriteCond %{REQUEST_URI} ^/releases
551 RewriteRule /releases(.*) https://release.immae.eu$1 [P,L]
552 '';
553 })
554 { # Should go last, default fallback
555 listen = [ { ip = "*"; port = 80; } ];
556 hostName = "redirectSSL";
557 serverAliases = [ "*" ];
558 enableSSL = false;
559 logFormat = "combinedVhost";
560 documentRoot = "/var/lib/acme/acme-challenge";
561 extraConfig = ''
562 RewriteEngine on
563 RewriteCond "%{REQUEST_URI}" "!^/\.well-known"
564 RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301]
565 # To redirect in specific "VirtualHost *:80", do
566 # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1
567 # rather than rewrite
568 '';
569 }
570 ];
571 };
572
573 security.pam.services = let
574 pam_ldap = pkgs.pam_ldap;
575 pam_ldap_mysql = assert checkEnv "NIXOPS_MYSQL_PAM_PASSWORD";
576 pkgs.writeText "mysql.conf" ''
577 host ldap.immae.eu
578 base dc=immae,dc=eu
579 binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
580 bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"}
581 pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
582 '';
583 in [
584 {
585 name = "mysql";
586 text = ''
587 # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/
588 auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
589 account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
590 '';
591 }
592 ];
593
594 # FIXME: backup
595 # Nextcloud: 14
596 services.redis = rec {
597 enable = true;
598 bind = "127.0.0.1";
599 unixSocket = "/run/redis/redis.sock";
600 extraConfig = ''
601 unixsocketperm 777
602 maxclients 1024
603 '';
604 };
605
606 # FIXME: initial sync
607 # FIXME: backup
608 # FIXME: restart after pam
609 # FIXME: pam access doesn’t work (because of php module)
610 # FIXME: ssl
611 services.mysql = rec {
612 enable = true;
613 package = pkgs.mariadb;
614 };
615
616 # FIXME: initial sync
617 # FIXME: backup
618 # FIXME: ssl
619 services.postgresql = rec {
620 enable = true;
621 package = pkgs.postgresql;
622 enableTCPIP = true;
623 extraConfig = ''
624 max_connections = 100
625 wal_level = logical
626 shared_buffers = 128MB
627 max_wal_size = 1GB
628 min_wal_size = 80MB
629 log_timezone = 'Europe/Paris'
630 datestyle = 'iso, mdy'
631 timezone = 'Europe/Paris'
632 lc_messages = 'en_US.UTF-8'
633 lc_monetary = 'en_US.UTF-8'
634 lc_numeric = 'en_US.UTF-8'
635 lc_time = 'en_US.UTF-8'
636 default_text_search_config = 'pg_catalog.english'
637 # ssl = on
638 # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem'
639 # ssl_key_file = '/var/lib/acme/eldiron/key.pem'
640 '';
641 authentication = ''
642 local all postgres ident
643 local all all md5
644 host all all samehost md5
645 host all all 178.33.252.96/32 md5
646 host all all 188.165.209.148/32 md5
647 #host all all all pam
648 '';
649 };
650
651 services.cron = {
652 enable = true;
653 systemCronJobs = let
654 stats = domain: conf: let
655 d = pkgs.writeScriptBin "stats-${domain}" "${pkgs.gnused}/bin/sed -n '/\\['$(LC_ALL=C ${pkgs.coreutils}/bin/date -d yesterday +'%d\\/%b\\/%Y')'/ p' /var/log/httpd/access_log-${domain} | ${pkgs.goaccess}/bin/goaccess -o /var/lib/goaccess/${domain}/index.html -p ${conf}";
656 in "${d}/bin/stats-${domain}";
657 in [
658 "5 0 * * * root ${stats "aten.pro" ./packages/aten_goaccess.conf}"
659 "5 0 * * * root ${stats "ludivinecassal.com" ./packages/ludivinecassal_goaccess.conf}"
660 "5 0 * * * root ${stats "piedsjaloux.fr" ./packages/piedsjaloux_goaccess.conf}"
661 "5 0 * * * root ${stats "osteopathe-cc.fr" ./packages/chloe_goaccess.conf}"
662 ];
663 };
664
665 systemd.services.tt-rss = {
666 description = "Tiny Tiny RSS feeds update daemon";
667 serviceConfig = {
668 User = "wwwrun";
669 ExecStart = "${pkgs.php}/bin/php ${mypkgs.ttrss.webRoot}/update.php --daemon";
670 StandardOutput = "syslog";
671 StandardError = "syslog";
672 PermissionsStartOnly = true;
673 };
674
675 wantedBy = [ "multi-user.target" ];
676 requires = ["postgresql.service"];
677 after = ["network.target" "postgresql.service"];
678 };
679 };
680 }