aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/isabelle/iridologie.nix
blob: 14296bf3957aa7ce1d6165c6c82cb27096caef69 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{ lib, pkgs, config,  ... }:
let
  icfg = config.myEnv.websites.isabelle.iridologie;
  cfg = config.myServices.websites.isabelle.iridologie;
  app = pkgs.callPackage ./iridologie_app {
    inherit (icfg) environment;
    inherit (pkgs.webapps) spip;
    varDir = "/var/lib/isabelle_iridologie";
  };

  apacheUser = config.services.httpd.Prod.user;
  apacheGroup = config.services.httpd.Prod.group;
  webappdir = config.services.websites.webappDirsPaths.isabelle_iridologie;
  secretsPath = config.secrets.fullPaths."websites/isabelle/iridologie";
in {
  options.myServices.websites.isabelle.iridologie.enable = lib.mkEnableOption "enable Iridologie's website";

  config = lib.mkIf cfg.enable {
    services.duplyBackup.profiles.isabelle_iridologie.rootDir = app.varDir;
    services.duplyBackup.profiles.isabelle_iridologie.remotes = ["eriomem" "ovh"];
    secrets.keys = [
      {
        dest = "websites/isabelle/iridologie";
        user = apacheUser;
        group = apacheGroup;
        permissions = "0400";
        text = ''
          SetEnv SPIP_CONFIG_DIR     "${./config}"
          SetEnv SPIP_VAR_DIR        "${app.varDir}"
          SetEnv SPIP_SITE           "iridologie-${app.environment}"
          SetEnv SPIP_LDAP_BASE      "dc=immae,dc=eu"
          SetEnv SPIP_LDAP_HOST      "ldaps://ldap.immae.eu"
          SetEnv SPIP_LDAP_SEARCH_DN "${icfg.ldap.dn}"
          SetEnv SPIP_LDAP_SEARCH_PW "${icfg.ldap.password}"
          SetEnv SPIP_LDAP_SEARCH    "${icfg.ldap.filter}"
          SetEnv SPIP_MYSQL_HOST     "${icfg.mysql.host}"
          SetEnv SPIP_MYSQL_PORT     "${icfg.mysql.port}"
          SetEnv SPIP_MYSQL_DB       "${icfg.mysql.database}"
          SetEnv SPIP_MYSQL_USER     "${icfg.mysql.user}"
          SetEnv SPIP_MYSQL_PASSWORD "${icfg.mysql.password}"
        '';
      }
    ];
    services.webstats.sites = [ { name = "iridologie.icommandeur.org"; } ];

    systemd.services.phpfpm-isabelle_iridologie.after = lib.mkAfter [ "mysql.service" ];
    systemd.services.phpfpm-isabelle_iridologie.wants = [ "mysql.service" ];
    services.phpfpm.pools.isabelle_iridologie = {
      user = config.services.httpd.Prod.user;
      group = config.services.httpd.Prod.group;
      settings = {
        "listen.owner" = "${apacheUser}";
        "listen.group" = "${apacheGroup}";
        "php_admin_value[upload_max_filesize]" = "20M";
        "php_admin_value[post_max_size]" = "20M";
        #"php_admin_flag[log_errors]" = "on";
        "php_admin_value[open_basedir]" = "${app.spipConfig}:${./config}:${app}:${app.varDir}:/tmp";
        "php_admin_value[session.save_path]" = "${app.varDir}/phpSessions";
        "pm" = "dynamic";
        "pm.max_children" = "20";
        "pm.start_servers" = "2";
        "pm.min_spare_servers" = "1";
        "pm.max_spare_servers" = "3";
      };
      phpPackage = pkgs.php72;
    };
    system.activationScripts.isabelle_iridologie = {
      deps = [ "wrappers" ];
      text = ''
        install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir} ${app.varDir}/IMG ${app.varDir}/tmp ${app.varDir}/local
        install -m 0750 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir}/phpSessions
      '';
    };
    services.websites.webappDirs.isabelle_iridologie = app.webRoot;
    services.websites.env.production.modules = [ "proxy_fcgi" ];
    services.websites.env.production.vhostConfs.isabelle_iridologie = {
      certName     = "isabelle";
      addToCerts   = true;
      hosts        = [ "iridologie.icommandeur.org" "icommandeur.org" "www.icommandeur.org" ];
      root         = webappdir;
      extraConfig  = [
        ''
          RewriteEngine On
          RewriteCond "%{HTTP_HOST}" "!^iridologie\.icommandeur\.org$" [NC]
          RewriteRule ^(.+)$ https://iridologie.icommandeur.org$1 [R=302,L]

          Include ${secretsPath}

          RewriteEngine On

          <FilesMatch "\.php$">
            SetHandler "proxy:unix:${config.services.phpfpm.pools.isabelle_iridologie.socket}|fcgi://localhost"
          </FilesMatch>

          <Directory ${webappdir}>
            DirectoryIndex index.php index.htm index.html
            Options -Indexes +FollowSymLinks +MultiViews +Includes
            Include ${webappdir}/htaccess.txt

            AllowOverride AuthConfig FileInfo Limit
            Require all granted
          </Directory>

          <DirectoryMatch "${webappdir}/squelettes">
            Require all denied
          </DirectoryMatch>

          <FilesMatch "(.htaccess|rewrite-rules|.gitignore)$">
            Require all denied
          </FilesMatch>

          Use Stats iridologie.icommandeur.org
          ''
      ];
    };
    services.websites.env.production.watchPaths = [
      secretsPath
    ];
  };
}