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