aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/tools/tools/shaarli.nix
blob: d128465b8bc33c87872afd73fe3a3c3a5fdee6af (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
{ lib, env, stdenv, fetchurl, shaarli, config }:
let
  varDir = "/var/lib/shaarli";
in rec {
  activationScript = ''
    install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
      ${varDir}/cache ${varDir}/pagecache ${varDir}/tmp ${varDir}/data \
      ${varDir}/phpSessions
    '';
  webRoot = shaarli varDir;
  apache = rec {
    user = "wwwrun";
    group = "wwwrun";
    modules =  [ "proxy_fcgi" "rewrite" "env" ];
    root = webRoot;
    vhostConf = socket: ''
      Alias /Shaarli "${root}"

      Include ${config.secrets.fullPaths."webapps/tools-shaarli"}
      <Location /Shaarli>
        Header set Access-Control-Allow-Origin "*"
        Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
        Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization, Client-Security-Token, Accept-Encoding"
      </Location>
      <Directory "${root}">
        DirectoryIndex index.php index.htm index.html
        Options Indexes FollowSymLinks MultiViews Includes
        AllowOverride All
        Require all granted
        <FilesMatch "\.php$">
          SetHandler "proxy:unix:${socket}|fcgi://localhost"
        </FilesMatch>
      </Directory>
      '';
  };
  keys."webapps/tools-shaarli" = {
    user = apache.user;
    group = apache.group;
    permissions = "0400";
    text = ''
      SetEnv SHAARLI_LDAP_PASSWORD "${env.ldap.password}"
      SetEnv SHAARLI_LDAP_DN       "${env.ldap.dn}"
      SetEnv SHAARLI_LDAP_HOST     "ldaps://${env.ldap.host}"
      SetEnv SHAARLI_LDAP_BASE     "${env.ldap.base}"
      SetEnv SHAARLI_LDAP_FILTER   "${env.ldap.filter}"
      '';
  };
  phpFpm = rec {
    serviceDeps = [ "openldap.service" ];
    basedir = builtins.concatStringsSep ":" [ webRoot varDir ];
    pool = {
      "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]" = "ShaarliPHPSESSID";
      "php_admin_value[open_basedir]" = "${basedir}:/tmp";
      "php_admin_value[session.save_path]" = "${varDir}/phpSessions";
      "php_admin_value[upload_max_filesize]" = "200M";
      "php_admin_value[post_max_size]" = "200M";
    };
  };
}