aboutsummaryrefslogtreecommitdiff
path: root/pkgs/webapps/dokuwiki/default.nix
blob: 874f0d87696f69b2ba6d4a21006414dedf2eead1 (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
{ varDir ? "/var/lib/dokuwiki", preload ? "", lib, callPackage, stdenv, mylibs, writeText }:
let
  preloadFile = plugins: let preloads = [preload]
      ++ builtins.concatMap (p: lib.optional (lib.hasAttr "preload" p) (p.preload p)) plugins;
    in writeText "preload.php" (''
      <?php
      '' + builtins.concatStringsSep "\n" preloads
    );
  pluginNames = [ "farmer" "todo" ];
  allPlugins = lib.attrsets.genAttrs pluginNames
    (name: callPackage (./plugins + "/${name}.nix") {});
  toPassthru = pkg: plugins: {
    inherit plugins varDir allPlugins;
    withPlugins = withPlugins pkg;
  };
  withPlugins = pkg: toPlugins:
    let
      plugins = toPlugins allPlugins;
      toInstallPlugin = n:
        "ln -sf ${n} $out/lib/plugins/${n.pluginName}";
      newDokuwiki = pkg.overrideAttrs(old: {
        installPhase = old.installPhase + "\n" + builtins.concatStringsSep "\n" (map toInstallPlugin plugins);
        installPreloadPhase = ''
          cp ${preloadFile (pkg.plugins ++ plugins)} $out/inc/preload.php
        '';
        passthru = toPassthru newDokuwiki (pkg.plugins ++ plugins);
      });
    in newDokuwiki;
  package = stdenv.mkDerivation (mylibs.fetchedGithub ./dokuwiki.json // rec {
    phases = "unpackPhase buildPhase installPhase installPreloadPhase fixupPhase";
    buildPhase = ''
      mv conf conf.dist
      mv data data.dist
    '';
    installPhase = ''
      cp -a . $out
      ln -sf ${varDir}/{conf,data} $out/
      ln -sf ${varDir}/conf/.htaccess $out/
    '';
    installPreloadPhase = ''
      cp ${preloadFile []} $out/inc/preload.php
      '';
    passthru = toPassthru package [];
  });
in package