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