aboutsummaryrefslogtreecommitdiff
path: root/nixops/modules/websites/tools/tools/dokuwiki.nix
blob: 2cd19f10a8698772a18018202ea15ce0f88131e4 (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
{ lib, php, stdenv, writeText, fetchedGithub }:
let
  dokuwiki = let
    plugins = {
      farmer = stdenv.mkDerivation (fetchedGithub ./dokuwiki-plugin-farmer.json // rec {
        installPhase = ''
          mkdir $out
          cp -a * $out/
        '';
      });
      todo = stdenv.mkDerivation (fetchedGithub ./dokuwiki-plugin-todo.json // rec {
        installPhase = ''
          mkdir $out
          cp -a * $out/
        '';
      });
    };
    preload = writeText "preload.php" ''
      <?php
      # farm setup by farmer plugin
      if(file_exists('${plugins.farmer}/DokuWikiFarmCore.php'))
      {
          include('${plugins.farmer}/DokuWikiFarmCore.php');
      }
      '';
  in rec {
    varDir = "/var/lib/dokuwiki";
    activationScript = {
      deps = [ "wrappers" ];
      text = ''
        if [ ! -d ${varDir} ]; then
          install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
            ${varDir}/animals
          cp -a ${webRoot}/conf.dist ${varDir}/conf
          cp -a ${webRoot}/data.dist ${varDir}/data
          cp -a ${webRoot}/
          chown -R ${apache.user}:${apache.user} ${varDir}/config ${varDir}/data
          chmod -R 755 ${varDir}/config ${varDir}/data
        fi
        install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
      '';
    };
    webRoot = stdenv.mkDerivation (fetchedGithub ./dokuwiki.json // rec {
      buildPhase = ''
        mv conf conf.dist
        mv data data.dist
      '';
      installPhase = ''
        cp -a . $out
        cp ${preload} $out/inc/preload.php
        ln -sf ${varDir}/{conf,data} $out/
        ln -sf ${varDir}/conf/.htaccess $out/
        ${builtins.concatStringsSep "\n" (
          lib.attrsets.mapAttrsToList (name: value: "ln -sf ${value} $out/lib/plugins/${name}") plugins
        )}
      '';
    });
    apache = rec {
      user = "wwwrun";
      group = "wwwrun";
      modules = [ "proxy_fcgi" ];
      webappName = "tools_dokuwiki";
      root = "/run/current-system/webapps/${webappName}";
      vhostConf = ''
        Alias /dokuwiki "${root}"
        <Directory "${root}">
          DirectoryIndex index.php
          <FilesMatch "\.php$">
            SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
          </FilesMatch>

          AllowOverride All
          Options +FollowSymlinks
          Require all granted
        </Directory>
        '';
    };
    phpFpm = rec {
      serviceDeps = [ "openldap.service" ];
      basedir = builtins.concatStringsSep ":" (
        [ webRoot varDir ]
        ++ lib.attrsets.mapAttrsToList (name: value: value) plugins);
      socket = "/var/run/phpfpm/dokuwiki.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] = DokuwikiPHPSESSID
        php_admin_value[open_basedir] = "${basedir}:/tmp"
        php_admin_value[session.save_path] = "${varDir}/phpSessions"
        '';
    };
  };
in 
  dokuwiki