]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - nixops/modules/websites/tools/tools/dokuwiki.nix
Add dokuwiki
[perso/Immae/Config/Nix.git] / nixops / modules / websites / tools / tools / dokuwiki.nix
diff --git a/nixops/modules/websites/tools/tools/dokuwiki.nix b/nixops/modules/websites/tools/tools/dokuwiki.nix
new file mode 100644 (file)
index 0000000..5affddb
--- /dev/null
@@ -0,0 +1,99 @@
+{ 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 = {
+      user = "wwwrun";
+      group = "wwwrun";
+      modules = [ "proxy_fcgi" ];
+      vhostConf = ''
+        Alias /dokuwiki "${webRoot}"
+        <Directory "${webRoot}">
+          DirectoryIndex index.php
+          <FilesMatch "\.php$">
+            SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
+          </FilesMatch>
+
+          AllowOverride All
+          Options +FollowSymlinks
+          Require all granted
+        </Directory>
+        '';
+    };
+    phpFpm = rec {
+      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