]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - nixops/modules/websites/tools/tools/dokuwiki.nix
Add dokuwiki
[perso/Immae/Config/Nix.git] / nixops / modules / websites / tools / tools / dokuwiki.nix
1 { lib, php, stdenv, writeText, fetchedGithub }:
2 let
3 dokuwiki = let
4 plugins = {
5 farmer = stdenv.mkDerivation (fetchedGithub ./dokuwiki-plugin-farmer.json // rec {
6 installPhase = ''
7 mkdir $out
8 cp -a * $out/
9 '';
10 });
11 todo = stdenv.mkDerivation (fetchedGithub ./dokuwiki-plugin-todo.json // rec {
12 installPhase = ''
13 mkdir $out
14 cp -a * $out/
15 '';
16 });
17 };
18 preload = writeText "preload.php" ''
19 <?php
20 # farm setup by farmer plugin
21 if(file_exists('${plugins.farmer}/DokuWikiFarmCore.php'))
22 {
23 include('${plugins.farmer}/DokuWikiFarmCore.php');
24 }
25 '';
26 in rec {
27 varDir = "/var/lib/dokuwiki";
28 activationScript = {
29 deps = [ "wrappers" ];
30 text = ''
31 if [ ! -d ${varDir} ]; then
32 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
33 ${varDir}/animals
34 cp -a ${webRoot}/conf.dist ${varDir}/conf
35 cp -a ${webRoot}/data.dist ${varDir}/data
36 cp -a ${webRoot}/
37 chown -R ${apache.user}:${apache.user} ${varDir}/config ${varDir}/data
38 chmod -R 755 ${varDir}/config ${varDir}/data
39 fi
40 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
41 '';
42 };
43 webRoot = stdenv.mkDerivation (fetchedGithub ./dokuwiki.json // rec {
44 buildPhase = ''
45 mv conf conf.dist
46 mv data data.dist
47 '';
48 installPhase = ''
49 cp -a . $out
50 cp ${preload} $out/inc/preload.php
51 ln -sf ../../../../../${varDir}/{conf,data} $out/
52 ln -sf ../../../../../${varDir}/conf/.htaccess $out/
53 ${builtins.concatStringsSep "\n" (
54 lib.attrsets.mapAttrsToList (name: value: "ln -sf ${value} $out/lib/plugins/${name}") plugins
55 )}
56 '';
57 });
58 apache = {
59 user = "wwwrun";
60 group = "wwwrun";
61 modules = [ "proxy_fcgi" ];
62 vhostConf = ''
63 Alias /dokuwiki "${webRoot}"
64 <Directory "${webRoot}">
65 DirectoryIndex index.php
66 <FilesMatch "\.php$">
67 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
68 </FilesMatch>
69
70 AllowOverride All
71 Options +FollowSymlinks
72 Require all granted
73 </Directory>
74 '';
75 };
76 phpFpm = rec {
77 basedir = builtins.concatStringsSep ":" (
78 [ webRoot varDir ]
79 ++ lib.attrsets.mapAttrsToList (name: value: value) plugins);
80 socket = "/var/run/phpfpm/dokuwiki.sock";
81 pool = ''
82 listen = ${socket}
83 user = ${apache.user}
84 group = ${apache.group}
85 listen.owner = ${apache.user}
86 listen.group = ${apache.group}
87 pm = ondemand
88 pm.max_children = 60
89 pm.process_idle_timeout = 60
90
91 ; Needed to avoid clashes in browser cookies (same domain)
92 php_value[session.name] = DokuwikiPHPSESSID
93 php_admin_value[open_basedir] = "${basedir}:/tmp"
94 php_admin_value[session.save_path] = "${varDir}/phpSessions"
95 '';
96 };
97 };
98 in
99 dokuwiki