aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/isabelle/aten_production.nix
blob: 8e33f0f26b30680ea1abd40ea384977306bf7ea6 (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
{ lib, pkgs, config,  ... }:
let
  secrets = config.myEnv.websites.isabelle.aten_production;
  app = pkgs.webapps.aten.override { environment = secrets.environment; };
  cfg = config.myServices.websites.isabelle.aten_production;
  pcfg = config.services.phpApplication;
in {
  options.myServices.websites.isabelle.aten_production.enable = lib.mkEnableOption "enable Aten's website in production";

  config = lib.mkIf cfg.enable {
    services.duplyBackup.profiles.aten_prod.rootDir = app.varDir;
    services.webstats.sites = [ { name = "aten.pro"; } ];
    services.phpApplication.apps.aten_prod = {
      websiteEnv = "production";
      httpdUser = config.services.httpd.Prod.user;
      httpdGroup = config.services.httpd.Prod.group;
      httpdWatchFiles = [
        config.secrets.fullPaths."webapps/${app.environment}-aten"
      ];
      inherit (app) webRoot varDir;
      inherit app;
      serviceDeps = [ "postgresql.service" ];
      preStartActions = [
        "APP_ENV=${app.environment} ./bin/console --env=${app.environment} cache:clear --no-warmup"
      ];
      phpOpenbasedir = [ "/tmp" ];
      phpPool = ''
        php_admin_value[upload_max_filesize] = 20M
        php_admin_value[post_max_size] = 20M
        ;php_admin_flag[log_errors] = on
        pm = dynamic
        pm.max_children = 20
        pm.start_servers = 2
        pm.min_spare_servers = 1
        pm.max_spare_servers = 3
      '';
    };

    secrets.keys = [{
      dest = "webapps/${app.environment}-aten";
      user = config.services.httpd.Prod.user;
      group = config.services.httpd.Prod.group;
      permissions = "0400";
      text = let
        # cf:
        #   https://secure.php.net/manual/fr/function.parse-url.php
        #   vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php#parseDatabaseUrlQuery
        psql_url = with secrets.postgresql; "pdo-pgsql://${user}:${password}@invalid:${port}/${database}?host=${socket}";
      in ''
        SetEnv APP_ENV      "${app.environment}"
        SetEnv APP_SECRET   "${secrets.secret}"
        SetEnv DATABASE_URL "${psql_url}"
        '';
    }];
    services.websites.env.production.vhostConfs.aten_prod = {
      certName     = "aten";
      certMainHost = "aten.pro";
      hosts       = [ "aten.pro" "www.aten.pro" ];
      root        = pcfg.webappDirs.aten_prod;
      extraConfig = [
        ''
        <FilesMatch "\.php$">
          SetHandler "proxy:unix:${pcfg.phpListenPaths.aten_prod}|fcgi://localhost"
        </FilesMatch>

        Include ${config.secrets.fullPaths."webapps/${app.environment}-aten"}

        Use Stats aten.pro

        <Location /backend>
          Use LDAPConnect
          Require ldap-group   cn=aten.pro,cn=httpd,ou=services,dc=immae,dc=eu
          ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
        </Location>

        <Directory ${pcfg.webappDirs.aten_prod}>
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride All
          Require all granted
          DirectoryIndex index.php
          FallbackResource /index.php
        </Directory>
        ''
      ];
    };
  };
}