]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/naturaloutil/production.nix
Replace myPhpfpm with correct overrides
[perso/Immae/Config/Nix.git] / modules / private / websites / naturaloutil / production.nix
1 { lib, pkgs, config, myconfig, ... }:
2 let
3 adminer = pkgs.callPackage ../commons/adminer.nix {};
4 cfg = config.myServices.websites.naturaloutil.production;
5 varDir = "/var/lib/ftp/jerome";
6 env = myconfig.env.websites.jerome;
7 in {
8 options.myServices.websites.naturaloutil.production.enable = lib.mkEnableOption "enable Naturaloutil's website";
9
10 config = lib.mkIf cfg.enable {
11 services.webstats.sites = [ { name = "naturaloutil.immae.eu"; } ];
12
13 security.acme.certs."ftp".extraDomains."naturaloutil.immae.eu" = null;
14
15 secrets.keys = [{
16 dest = "webapps/prod-naturaloutil";
17 user = "wwwrun";
18 group = "wwwrun";
19 permissions = "0400";
20 text = ''
21 <?php
22 $mysql_user = '${env.mysql.user}' ;
23 $mysql_server = '${env.mysql.host}' ;
24 $mysql_base = '${env.mysql.name}' ;
25 $mysql_password = '${env.mysql.password}' ;
26 //connect to db
27 $db = mysqli_init();
28 ${if env.mysql.host != "localhost" then ''
29 mysqli_options ($db, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
30 $db->ssl_set(NULL, NULL, "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt", NULL, NULL);
31 '' else ""}
32 $database = connect_db($db, $mysql_server, $mysql_base, $mysql_user, $mysql_password);
33 ?>
34 '';
35 }];
36 systemd.services.phpfpm-jerome.after = lib.mkAfter [ "mysql.service" ];
37 systemd.services.phpfpm-jerome.wants = [ "mysql.service" ];
38 services.phpfpm.pools.jerome = {
39 listen = "/run/phpfpm/naturaloutil.sock";
40 extraConfig = ''
41 user = wwwrun
42 group = wwwrun
43 listen.owner = wwwrun
44 listen.group = wwwrun
45
46 pm = ondemand
47 pm.max_children = 5
48 pm.process_idle_timeout = 60
49
50 env[BDD_CONNECT] = "/var/secrets/webapps/prod-naturaloutil"
51 php_admin_value[open_basedir] = "/var/secrets/webapps/prod-naturaloutil:${varDir}:/tmp"
52 '';
53 phpOptions = config.services.phpfpm.phpOptions + ''
54 extension=${pkgs.php}/lib/php/extensions/mysqli.so
55 '';
56 };
57 services.websites.production.modules = adminer.apache.modules ++ [ "proxy_fcgi" ];
58 services.websites.production.vhostConfs.naturaloutil = {
59 certName = "naturaloutil";
60 certMainHost = "naturaloutil.immae.eu";
61 hosts = ["naturaloutil.immae.eu" ];
62 root = varDir;
63 extraConfig = [
64 adminer.apache.vhostConf
65 ''
66 Use Stats naturaloutil.immae.eu
67 ServerAdmin ${env.server_admin}
68 ErrorLog "${varDir}/logs/error_log"
69 CustomLog "${varDir}/logs/access_log" combined
70
71 <FilesMatch "\.php$">
72 SetHandler "proxy:unix:/run/phpfpm/naturaloutil.sock|fcgi://localhost"
73 </FilesMatch>
74
75 <Directory ${varDir}/logs>
76 AllowOverride None
77 Require all denied
78 </Directory>
79 <Directory ${varDir}>
80 DirectoryIndex index.php index.htm index.html
81 Options Indexes FollowSymLinks MultiViews Includes
82 AllowOverride None
83 Require all granted
84 </Directory>
85 ''
86 ];
87 };
88 };
89 }