From af6a7a04869889b470c4dad6e0adc57482818d3a Mon Sep 17 00:00:00 2001 From: dadada Date: Mon, 30 Mar 2020 13:08:16 +0200 Subject: [PATCH] nixos/dokuwiki: add plugins and templates options Adds support for additional plugins and templates similarly to how wordpress.nix does it. Plugins and templates need to be packaged as in the example. --- nixos/modules/services/web-apps/dokuwiki.nix | 61 +++++++++++++++++++- nixos/tests/dokuwiki.nix | 38 +++++++++++- 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/web-apps/dokuwiki.nix b/nixos/modules/services/web-apps/dokuwiki.nix index 6378cf6507c4..7587c744ad51 100644 --- a/nixos/modules/services/web-apps/dokuwiki.nix +++ b/nixos/modules/services/web-apps/dokuwiki.nix @@ -3,7 +3,7 @@ let inherit (lib) mkEnableOption mkForce mkIf mkMerge mkOption optionalAttrs recursiveUpdate types; - inherit (lib) flatten mapAttrs mapAttrs' mapAttrsToList nameValuePair; + inherit (lib) concatMapStringsSep flatten mapAttrs mapAttrs' mapAttrsToList nameValuePair concatMapStringSep; eachSite = config.services.dokuwiki; stateDir = cfg: "/var/lib/dokuwiki/${cfg.hostName}"; @@ -50,6 +50,10 @@ let # symlink acl ln -s ${dokuwikiAclAuthConfig cfg} $out/share/dokuwiki/acl.auth.php + + # symlink additional plugin(s) and templates(s) + ${concatMapStringsSep "\n" (template: "ln -s ${template} $out/share/dokuwiki/lib/tpl/${template.name}") cfg.templates} + ${concatMapStringsSep "\n" (plugin: "ln -s ${plugin} $out/share/dokuwiki/lib/plugins/${plugin.name}") cfg.plugins} ''; }; @@ -155,6 +159,61 @@ let ''; }; + plugins = mkOption { + type = types.listOf types.path; + default = []; + description = '' + List of path(s) to respective plugin(s) which are copied from the 'plugin' directory. + These plugins need to be packaged before use, see example. + ''; + example = '' + # Let's package the icalevents plugin + plugin-icalevents = pkgs.stdenv.mkDerivation { + name = "icalevents"; + # Download the plugin from the dokuwiki site + src = pkgs.fetchurl { + url = https://github.com/real-or-random/dokuwiki-plugin-icalevents/releases/download/2017-06-16/dokuwiki-plugin-icalevents-2017-06-16.zip; + sha256 = "e40ed7dd6bbe7fe3363bbbecb4de481d5e42385b5a0f62f6a6ce6bf3a1f9dfa8"; + }; + sourceRoot = "."; + # We need unzip to build this package + buildInputs = [ pkgs.unzip ]; + # Installing simply means copying all files to the output directory + installPhase = "mkdir -p $out; cp -R * $out/"; + }; + + # And then pass this theme to the plugin list like this: + plugins = [ plugin-icalevents ]; + ''; + }; + + templates = mkOption { + type = types.listOf types.path; + default = []; + description = '' + List of path(s) to respective template(s) which are copied from the 'tpl' directory. + These templates need to be packaged before use, see example. + ''; + example = '' + # Let's package the bootstrap3 theme + template-bootstrap3 = pkgs.stdenv.mkDerivation { + name = "bootstrap3"; + # Download the theme from the dokuwiki site + src = pkgs.fetchurl { + url = https://github.com/giterlizzi/dokuwiki-template-bootstrap3/archive/v2019-05-22.zip; + sha256 = "4de5ff31d54dd61bbccaf092c9e74c1af3a4c53e07aa59f60457a8f00cfb23a6"; + }; + # We need unzip to build this package + buildInputs = [ pkgs.unzip ]; + # Installing simply means copying all files to the output directory + installPhase = "mkdir -p $out; cp -R * $out/"; + }; + + # And then pass this theme to the template list like this: + templates = [ template-bootstrap3 ]; + ''; + }; + poolConfig = mkOption { type = with types; attrsOf (oneOf [ str int bool ]); default = { diff --git a/nixos/tests/dokuwiki.nix b/nixos/tests/dokuwiki.nix index 65d2677dd3ab..62d8ec9f0b1c 100644 --- a/nixos/tests/dokuwiki.nix +++ b/nixos/tests/dokuwiki.nix @@ -1,13 +1,43 @@ import ./make-test-python.nix ({ pkgs, ... }: -{ +let + template-bootstrap3 = pkgs.stdenv.mkDerivation { + name = "bootstrap3"; + # Download the theme from the dokuwiki site + src = pkgs.fetchurl { + url = https://github.com/giterlizzi/dokuwiki-template-bootstrap3/archive/v2019-05-22.zip; + sha256 = "4de5ff31d54dd61bbccaf092c9e74c1af3a4c53e07aa59f60457a8f00cfb23a6"; + }; + # We need unzip to build this package + buildInputs = [ pkgs.unzip ]; + # Installing simply means copying all files to the output directory + installPhase = "mkdir -p $out; cp -R * $out/"; + }; + + + # Let's package the icalevents plugin + plugin-icalevents = pkgs.stdenv.mkDerivation { + name = "icalevents"; + # Download the plugin from the dokuwiki site + src = pkgs.fetchurl { + url = https://github.com/real-or-random/dokuwiki-plugin-icalevents/releases/download/2017-06-16/dokuwiki-plugin-icalevents-2017-06-16.zip; + sha256 = "e40ed7dd6bbe7fe3363bbbecb4de481d5e42385b5a0f62f6a6ce6bf3a1f9dfa8"; + }; + # We need unzip to build this package + buildInputs = [ pkgs.unzip ]; + sourceRoot = "."; + # Installing simply means copying all files to the output directory + installPhase = "mkdir -p $out; cp -R * $out/"; + }; + +in { name = "dokuwiki"; meta.maintainers = with pkgs.lib.maintainers; [ "1000101" ]; machine = { ... }: { services.dokuwiki."site1.local" = { acl = " "; - superUser = null; + superUser = "admin"; nginx = { forceSSL = false; enableACME = false; @@ -15,11 +45,13 @@ import ./make-test-python.nix ({ pkgs, ... }: }; services.dokuwiki."site2.local" = { acl = " "; - superUser = null; + superUser = "admin"; nginx = { forceSSL = false; enableACME = false; }; + templates = [ template-bootstrap3 ]; + plugins = [ plugin-icalevents ]; }; networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ]; };