]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - nixops/modules/websites/tools/tools/dokuwiki.nix
2cd19f10a8698772a18018202ea15ce0f88131e4
[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 = rec {
59 user = "wwwrun";
60 group = "wwwrun";
61 modules = [ "proxy_fcgi" ];
62 webappName = "tools_dokuwiki";
63 root = "/run/current-system/webapps/${webappName}";
64 vhostConf = ''
65 Alias /dokuwiki "${root}"
66 <Directory "${root}">
67 DirectoryIndex index.php
68 <FilesMatch "\.php$">
69 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
70 </FilesMatch>
71
72 AllowOverride All
73 Options +FollowSymlinks
74 Require all granted
75 </Directory>
76 '';
77 };
78 phpFpm = rec {
79 serviceDeps = [ "openldap.service" ];
80 basedir = builtins.concatStringsSep ":" (
81 [ webRoot varDir ]
82 ++ lib.attrsets.mapAttrsToList (name: value: value) plugins);
83 socket = "/var/run/phpfpm/dokuwiki.sock";
84 pool = ''
85 listen = ${socket}
86 user = ${apache.user}
87 group = ${apache.group}
88 listen.owner = ${apache.user}
89 listen.group = ${apache.group}
90 pm = ondemand
91 pm.max_children = 60
92 pm.process_idle_timeout = 60
93
94 ; Needed to avoid clashes in browser cookies (same domain)
95 php_value[session.name] = DokuwikiPHPSESSID
96 php_admin_value[open_basedir] = "${basedir}:/tmp"
97 php_admin_value[session.save_path] = "${varDir}/phpSessions"
98 '';
99 };
100 };
101 in
102 dokuwiki