From da9185d96462cf33f2da649d156f877b393e3920 Mon Sep 17 00:00:00 2001 From: Moritz 'e1mo' Fromm Date: Fri, 6 Jan 2023 14:42:43 +0100 Subject: [PATCH 1/2] nixosTests.dokuwiki: Deduplicate node configuration Also added two "quality of life" tests to ensure customisations to the dokuiwki package are not being discarded and both webserver configurations handle rewriting correctly. --- nixos/tests/dokuwiki.nix | 94 ++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/nixos/tests/dokuwiki.nix b/nixos/tests/dokuwiki.nix index 67657e89f74c..15ccea23cf55 100644 --- a/nixos/tests/dokuwiki.nix +++ b/nixos/tests/dokuwiki.nix @@ -30,6 +30,39 @@ let installPhase = "mkdir -p $out; cp -R * $out/"; }; + acronymsFile = pkgs.writeText "acronyms.local.conf" '' + r13y reproducibility + ''; + + dwWithAcronyms = pkgs.dokuwiki.overrideAttrs (prev: { + installPhase = prev.installPhase or "" + '' + ln -sf ${acronymsFile} $out/share/dokuwiki/conf/acronyms.local.conf + ''; + }); + + mkNode = webserver: { ... }: { + services.dokuwiki = { + inherit webserver; + + sites = { + "site1.local" = { + aclUse = false; + superUser = "admin"; + }; + "site2.local" = { + package = dwWithAcronyms; + usersFile = "/var/lib/dokuwiki/site2.local/users.auth.php"; + superUser = "admin"; + templates = [ template-bootstrap3 ]; + plugins = [ plugin-icalevents ]; + }; + }; + }; + + networking.firewall.allowedTCPPorts = [ 80 ]; + networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ]; + }; + in { name = "dokuwiki"; meta = with pkgs.lib; { @@ -40,47 +73,8 @@ in { }; nodes = { - dokuwiki_nginx = {...}: { - services.dokuwiki = { - sites = { - "site1.local" = { - aclUse = false; - superUser = "admin"; - }; - "site2.local" = { - usersFile = "/var/lib/dokuwiki/site2.local/users.auth.php"; - superUser = "admin"; - templates = [ template-bootstrap3 ]; - plugins = [ plugin-icalevents ]; - }; - }; - }; - - networking.firewall.allowedTCPPorts = [ 80 ]; - networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ]; - }; - - dokuwiki_caddy = {...}: { - services.dokuwiki = { - webserver = "caddy"; - sites = { - "site1.local" = { - aclUse = false; - superUser = "admin"; - }; - "site2.local" = { - usersFile = "/var/lib/dokuwiki/site2.local/users.auth.php"; - superUser = "admin"; - templates = [ template-bootstrap3 ]; - plugins = [ plugin-icalevents ]; - }; - }; - }; - - networking.firewall.allowedTCPPorts = [ 80 ]; - networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ]; - }; - + dokuwiki_nginx = mkNode "nginx"; + dokuwiki_caddy = mkNode "caddy"; }; testScript = '' @@ -102,10 +96,24 @@ in { machine.succeed("curl -sSfL http://site2.local/ | grep 'DokuWiki'") machine.succeed("curl -sSfL 'http://site2.local/doku.php?do=login' | grep 'Login'") - machine.succeed( + with subtest("ACL Operations"): + machine.succeed( "echo 'admin:$2y$10$ijdBQMzSVV20SrKtCna8gue36vnsbVm2wItAXvdm876sshI4uwy6S:Admin:admin@example.test:user' >> /var/lib/dokuwiki/site2.local/users.auth.php", "curl -sSfL -d 'u=admin&p=password' --cookie-jar cjar 'http://site2.local/doku.php?do=login'", "curl -sSfL --cookie cjar --cookie-jar cjar 'http://site2.local/doku.php?do=login' | grep 'Logged in as: Admin'", - ) + ) + + with subtest("Customizing Dokuwiki"): + machine.succeed( + "echo 'r13y is awesome!' >> /var/lib/dokuwiki/site2.local/data/pages/acronyms-test.txt", + "curl -sSfL 'http://site2.local/doku.php?id=acronyms-test' | grep 'r13y'", + ) + + # Just to ensure both Webserver configurations are consistent in allowing that + with subtest("Rewriting"): + machine.succeed( + "echo 'Hello, NixOS!' >> /var/lib/dokuwiki/site1.local/data/pages/rewrite-test.txt", + "curl -sSfL http://site1.local/rewrite-test | grep 'Hello, NixOS!'", + ) ''; }) From 055100611dd3f9cb8a414328f9ffc00cc6d2e8f7 Mon Sep 17 00:00:00 2001 From: Moritz 'e1mo' Fromm Date: Fri, 6 Jan 2023 14:49:38 +0100 Subject: [PATCH 2/2] nixos/dokuwiki: Simplify plugin fetching examples Also replaced apache httpd referenced with ones to caddy --- nixos/modules/services/web-apps/dokuwiki.nix | 42 +++++++++----------- nixos/tests/dokuwiki.nix | 31 ++++++--------- 2 files changed, 31 insertions(+), 42 deletions(-) diff --git a/nixos/modules/services/web-apps/dokuwiki.nix b/nixos/modules/services/web-apps/dokuwiki.nix index f0b3c7b2bcf8..744f4b50be41 100644 --- a/nixos/modules/services/web-apps/dokuwiki.nix +++ b/nixos/modules/services/web-apps/dokuwiki.nix @@ -173,18 +173,14 @@ let ''; example = literalExpression '' let - # Let's package the icalevents plugin - plugin-icalevents = pkgs.stdenv.mkDerivation { + plugin-icalevents = pkgs.stdenv.mkDerivation rec { 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"; + version = "2017-06-16"; + src = pkgs.fetchzip { + stripRoot = false; + url = "https://github.com/real-or-random/dokuwiki-plugin-icalevents/releases/download/''${version}/dokuwiki-plugin-icalevents-''${version}.zip"; + hash = "sha256-IPs4+qgEfe8AAWevbcCM9PnyI0uoyamtWeg4rEb+9Wc="; }; - 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: @@ -204,19 +200,17 @@ let ''; example = literalExpression '' let - # 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/"; + template-bootstrap3 = pkgs.stdenv.mkDerivation rec { + name = "bootstrap3"; + version = "2022-07-27"; + src = pkgs.fetchFromGitHub { + owner = "giterlizzi"; + repo = "dokuwiki-template-bootstrap3"; + rev = "v''${version}"; + hash = "sha256-B3Yd4lxdwqfCnfmZdp+i/Mzwn/aEuZ0ovagDxuR6lxo="; }; + installPhase = "mkdir -p $out; cp -R * $out/"; + }; # And then pass this theme to the template list like this: in [ template-bootstrap3 ] ''; @@ -276,8 +270,8 @@ in Further nginx configuration can be done by adapting `services.nginx.virtualHosts.`. See [](#opt-services.nginx.virtualHosts) for further information. - Further apache2 configuration can be done by adapting `services.httpd.virtualHosts.`. - See [](#opt-services.httpd.virtualHosts) for further information. + Further caddy configuration can be done by adapting `services.caddy.virtualHosts.`. + See [](#opt-services.caddy.virtualHosts) for further information. ''; }; diff --git a/nixos/tests/dokuwiki.nix b/nixos/tests/dokuwiki.nix index 15ccea23cf55..d7c9e483f690 100644 --- a/nixos/tests/dokuwiki.nix +++ b/nixos/tests/dokuwiki.nix @@ -1,32 +1,27 @@ import ./make-test-python.nix ({ pkgs, ... }: let - template-bootstrap3 = pkgs.stdenv.mkDerivation { + template-bootstrap3 = pkgs.stdenv.mkDerivation rec { 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"; + version = "2022-07-27"; + src = pkgs.fetchFromGitHub { + owner = "giterlizzi"; + repo = "dokuwiki-template-bootstrap3"; + rev = "v${version}"; + hash = "sha256-B3Yd4lxdwqfCnfmZdp+i/Mzwn/aEuZ0ovagDxuR6lxo="; }; - # We need unzip to build this package - nativeBuildInputs = [ 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 { + plugin-icalevents = pkgs.stdenv.mkDerivation rec { 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"; + version = "2017-06-16"; + src = pkgs.fetchzip { + stripRoot = false; + url = "https://github.com/real-or-random/dokuwiki-plugin-icalevents/releases/download/${version}/dokuwiki-plugin-icalevents-${version}.zip"; + hash = "sha256-IPs4+qgEfe8AAWevbcCM9PnyI0uoyamtWeg4rEb+9Wc="; }; - # We need unzip to build this package - nativeBuildInputs = [ pkgs.unzip ]; - sourceRoot = "."; - # Installing simply means copying all files to the output directory installPhase = "mkdir -p $out; cp -R * $out/"; };