aboutsummaryrefslogtreecommitdiff
path: root/systems/eldiron/websites/performance/default.nix
blob: 23f754afec6a04bd444cecff0f9466d01a5fb7d4 (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
{ pkgs, lib, config, ... }:
let
  env = config.myEnv.tools.status_engine;
  package = pkgs.status-engine-interface.override({ config_file = config.secrets.fullPaths."status_engine_ui"; });
  apacheRoot = "${package}/public";
  cfg = config.myServices.websites.tools.performance;
in
{
  options.myServices.websites.tools.performance = {
    enable = lib.mkEnableOption "Enable performance website";
  };

  config = lib.mkIf cfg.enable {
    myServices.dns.zones."immae.eu".subdomains.performance =
      with config.myServices.dns.helpers; ips servers.eldiron.ips.main;

    secrets.keys = {
      status_engine_ui = {
        permissions = "0400";
        user = "wwwrun";
        group = "wwwrun";
        text = ''
          allow_anonymous: 0
          anonymous_can_submit_commands: 0
          urls_without_login:
            - login
            - loginstate
          auth_type: ldap
          ldap_server: ${env.ldap.host}
          ldap_use_ssl: 1
          ldap_port: 636
          ldap_bind_dn: ${env.ldap.dn}
          ldap_bind_password: ${env.ldap.password}
          ldap_base_dn: ${env.ldap.base}
          ldap_filter: "${env.ldap.filter}"
          ldap_attribute:
            - memberOf
          use_crate: 0
          use_mysql: 1
          mysql:
              host: 127.0.0.1
              port: ${builtins.toString env.mysql.port}
              username: ${env.mysql.user}
              password: ${env.mysql.password}
              database: ${env.mysql.database}
          display_perfdata: 1
          perfdata_backend: mysql
        '';
      };
    };

    services.websites.env.tools.modules = [ "proxy_fcgi" ];

    security.acme.certs.eldiron.extraDomainNames = [ "performance.immae.eu" ];
    services.websites.env.tools.vhostConfs.performance = {
      certName   = "eldiron";
      hosts      = [ "performance.immae.eu" ];
      root       = apacheRoot;
      extraConfig = [
        ''
          <Directory ${apacheRoot}>
            DirectoryIndex index.html
            AllowOverride None
            Require all granted
            <FilesMatch "\.php$">
              SetHandler "proxy:unix:${config.services.phpfpm.pools.status_engine.socket}|fcgi://localhost"
            </FilesMatch>
          </Directory>
        ''
      ];
    };

    services.phpfpm.pools.status_engine = {
      user = "wwwrun";
      group = "wwwrun";
      settings = {
        "listen.owner" = "wwwrun";
        "listen.group" = "wwwrun";
        "pm" = "dynamic";
        "pm.max_children" = "60";
        "pm.start_servers" = "2";
        "pm.min_spare_servers" = "1";
        "pm.max_spare_servers" = "10";

        "php_admin_value[session.save_handler]" = "redis";
        "php_admin_value[session.save_path]" = "'unix:///run/redis-php-sessions/redis.sock?persistent=1&prefix=Tools:StatusEngine:'";
        "php_admin_value[open_basedir]" = "${package}:/tmp:${config.secrets.fullPaths."status_engine_ui"}";
      };
      phpPackage = pkgs.php74.withExtensions({ enabled, all }: enabled ++ [ all.redis ]);
    };

  };
}