aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/tools/tools/rainloop.nix
blob: dbf0f248e50773c7bc1351b5989bc5b824fa5eda (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
{ lib, pkgs, writeText, stdenv, fetchurl }:
rec {
  varDir = "/var/lib/rainloop";
  activationScript = {
    deps = [ "wrappers" ];
    text = ''
      install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir}
      install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
      install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/data
    '';
  };
  webRoot = pkgs.rainloop-community.override { dataPath = "${varDir}/data"; };
  apache = rec {
    user = "wwwrun";
    group = "wwwrun";
    modules = [ "proxy_fcgi" ];
    webappName = "tools_rainloop";
    root = "/run/current-system/webapps/${webappName}";
    vhostConf = ''
    Alias /rainloop "${root}"
    <Directory "${root}">
      DirectoryIndex index.php
      AllowOverride All
      Options -FollowSymlinks
      Require all granted

      <FilesMatch "\.php$">
        SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
      </FilesMatch>
    </Directory>

    <DirectoryMatch "${root}/data">
      Require all denied
    </DirectoryMatch>
    '';
  };
  phpFpm = rec {
    serviceDeps = [ "postgresql.service" ];
    basedir = builtins.concatStringsSep ":" [ webRoot varDir ];
    socket = "/var/run/phpfpm/rainloop.sock";
    pool = ''
      listen = ${socket}
      user = ${apache.user}
      group = ${apache.group}
      listen.owner = ${apache.user}
      listen.group = ${apache.group}
      pm = ondemand
      pm.max_children = 60
      pm.process_idle_timeout = 60

      ; Needed to avoid clashes in browser cookies (same domain)
      php_value[session.name] = RainloopPHPSESSID
      php_admin_value[upload_max_filesize] = 200M
      php_admin_value[post_max_size] = 200M
      php_admin_value[open_basedir] = "${basedir}:/tmp"
      php_admin_value[session.save_path] = "${varDir}/phpSessions"
      '';
  };
}