aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/naturaloutil/production.nix
blob: 628e1291668a3c915d62710b3d6740cef2a9bf75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{ lib, pkgs, config,  ... }:
let
  adminer = pkgs.callPackage ../commons/adminer.nix {};
  cfg = config.myServices.websites.naturaloutil.production;
  varDir = "/var/lib/ftp/jerome";
  env = config.myEnv.websites.jerome;
in {
  options.myServices.websites.naturaloutil.production.enable = lib.mkEnableOption "enable Naturaloutil's website";

  config = lib.mkIf cfg.enable {
    services.webstats.sites = [ { name = "naturaloutil.immae.eu"; } ];

    security.acme.certs."ftp".extraDomains."naturaloutil.immae.eu" = null;

    secrets.keys = [{
      dest = "webapps/prod-naturaloutil";
      user = "wwwrun";
      group = "wwwrun";
      permissions = "0400";
      text = ''
        <?php
        $mysql_user = '${env.mysql.user}' ;
        $mysql_server = '${env.mysql.host}' ;
        $mysql_base = '${env.mysql.database}' ;
        $mysql_password = '${env.mysql.password}' ;
        //connect to db
        $db = mysqli_init();
        ${if env.mysql.host != "localhost" then ''
        mysqli_options ($db, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
        $db->ssl_set(NULL, NULL, "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt", NULL, NULL);
        '' else ""}
        $database = connect_db($db, $mysql_server, $mysql_base, $mysql_user, $mysql_password);
        ?>
      '';
    }];
    system.activationScripts.naturaloutil = {
      deps = [ "httpd" ];
      text = ''
        install -m 0755 -o wwwrun -g wwwrun -d /var/lib/php/sessions/naturaloutil
        '';
    };
    systemd.services.phpfpm-jerome.after = lib.mkAfter [ "mysql.service" ];
    systemd.services.phpfpm-jerome.wants = [ "mysql.service" ];
    services.phpfpm.pools.jerome = {
      listen = "/run/phpfpm/naturaloutil.sock";
      extraConfig = ''
        user = wwwrun
        group = wwwrun
        listen.owner = wwwrun
        listen.group = wwwrun

        pm = ondemand
        pm.max_children = 5
        pm.process_idle_timeout = 60

        env[BDD_CONNECT] = "/var/secrets/webapps/prod-naturaloutil"
        php_admin_value[open_basedir] = "/var/lib/php/sessions/naturaloutil:/var/secrets/webapps/prod-naturaloutil:${varDir}:/tmp"
        php_admin_value[session.save_path] = "/var/lib/php/sessions/naturaloutil"
        '';
      phpOptions = config.services.phpfpm.phpOptions + ''
        extension=${pkgs.php}/lib/php/extensions/mysqli.so
        '';
    };
    services.websites.env.production.modules = adminer.apache.modules ++ [ "proxy_fcgi" ];
    services.websites.env.production.vhostConfs.naturaloutil = {
      certName     = "naturaloutil";
      certMainHost = "naturaloutil.immae.eu";
      hosts        = ["naturaloutil.immae.eu" ];
      root         = varDir;
      extraConfig  = [
        adminer.apache.vhostConf
        ''
        Use Stats naturaloutil.immae.eu
        ServerAdmin ${env.server_admin}
        ErrorLog "${varDir}/logs/error_log"
        CustomLog "${varDir}/logs/access_log" combined

        <FilesMatch "\.php$">
          SetHandler "proxy:unix:/run/phpfpm/naturaloutil.sock|fcgi://localhost"
        </FilesMatch>

        <Directory ${varDir}/logs>
          AllowOverride None
          Require all denied
        </Directory>
        <Directory ${varDir}>
          DirectoryIndex index.php index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride None
          Require all granted
        </Directory>
          ''
      ];
    };
  };
}