1{ config, ... }:
2
3let
4 pkgs = config.node.pkgs;
5
6 template-bootstrap3 = pkgs.stdenv.mkDerivation rec {
7 name = "bootstrap3";
8 version = "2024-02-06";
9 src = pkgs.fetchFromGitHub {
10 owner = "giterlizzi";
11 repo = "dokuwiki-template-bootstrap3";
12 rev = "v${version}";
13 hash = "sha256-PSA/rHMkM/kMvOV7CP1byL8Ym4Qu7a4Rz+/aPX31x9k=";
14 };
15 installPhase = "mkdir -p $out; cp -R * $out/";
16 };
17
18 plugin-icalevents = pkgs.stdenv.mkDerivation rec {
19 name = "icalevents";
20 version = "2017-06-16";
21 src = pkgs.fetchzip {
22 stripRoot = false;
23 url = "https://github.com/real-or-random/dokuwiki-plugin-icalevents/releases/download/${version}/dokuwiki-plugin-icalevents-${version}.zip";
24 hash = "sha256-IPs4+qgEfe8AAWevbcCM9PnyI0uoyamtWeg4rEb+9Wc=";
25 };
26 installPhase = "mkdir -p $out; cp -R * $out/";
27 };
28
29 acronymsFile = pkgs.writeText "acronyms.local.conf" ''
30 r13y reproducibility
31 '';
32
33 dwWithAcronyms = pkgs.dokuwiki.overrideAttrs (prev: {
34 installPhase = prev.installPhase or "" + ''
35 ln -sf ${acronymsFile} $out/share/dokuwiki/conf/acronyms.local.conf
36 '';
37 });
38
39 mkNode =
40 webserver:
41 { ... }:
42 {
43 services.dokuwiki = {
44 inherit webserver;
45
46 sites = {
47 "site1.local" = {
48 templates = [ template-bootstrap3 ];
49 settings = {
50 useacl = false;
51 userewrite = true;
52 template = "bootstrap3";
53 };
54 };
55 "site2.local" = {
56 package = dwWithAcronyms;
57 usersFile = "/var/lib/dokuwiki/site2.local/users.auth.php";
58 plugins = [ plugin-icalevents ];
59 settings = {
60 useacl = true;
61 superuser = "admin";
62 title._file = titleFile;
63 plugin.dummy.empty = "This is just for testing purposes";
64 };
65 acl = [
66 {
67 page = "*";
68 actor = "@ALL";
69 level = "read";
70 }
71 {
72 page = "acl-test";
73 actor = "@ALL";
74 level = "none";
75 }
76 ];
77 pluginsConfig = {
78 authad = false;
79 authldap = false;
80 authmysql = false;
81 authpgsql = false;
82 tag = false;
83 icalevents = true;
84 };
85 };
86 };
87 };
88
89 services.caddy.virtualHosts = {
90 "site1.local".hostName = "http://site1.local";
91 "site2.local".hostName = "http://site2.local";
92 };
93
94 networking.firewall.allowedTCPPorts = [ 80 ];
95 networking.hosts."127.0.0.1" = [
96 "site1.local"
97 "site2.local"
98 ];
99 };
100
101 titleFile = pkgs.writeText "dokuwiki-title" "DokuWiki on site2";
102in
103{
104 name = "dokuwiki";
105 meta = with pkgs.lib; {
106 maintainers = with maintainers; [
107 _1000101
108 onny
109 e1mo
110 ];
111 };
112
113 nodes = {
114 dokuwiki_nginx = mkNode "nginx";
115 dokuwiki_caddy = mkNode "caddy";
116 };
117
118 testScript = ''
119
120 start_all()
121
122 dokuwiki_nginx.wait_for_unit("nginx")
123 dokuwiki_caddy.wait_for_unit("caddy")
124
125 site_names = ["site1.local", "site2.local"]
126
127 for machine in (dokuwiki_nginx, dokuwiki_caddy):
128 for site_name in site_names:
129 machine.wait_for_unit(f"phpfpm-dokuwiki-{site_name}")
130
131 machine.succeed("curl -sSfL http://site1.local/ | grep 'DokuWiki'")
132 machine.fail("curl -sSfL 'http://site1.local/doku.php?do=login' | grep 'Login'")
133
134 machine.succeed("curl -sSfL http://site2.local/ | grep 'DokuWiki on site2'")
135 machine.succeed("curl -sSfL 'http://site2.local/doku.php?do=login' | grep 'Login'")
136
137 with subtest("ACL Operations"):
138 machine.succeed(
139 "echo 'admin:$2y$10$ijdBQMzSVV20SrKtCna8gue36vnsbVm2wItAXvdm876sshI4uwy6S:Admin:admin@example.test:user' >> /var/lib/dokuwiki/site2.local/users.auth.php",
140 "curl -sSfL -d 'u=admin&p=password' --cookie-jar cjar 'http://site2.local/doku.php?do=login'",
141 "curl -sSfL --cookie cjar --cookie-jar cjar 'http://site2.local/doku.php?do=login' | grep 'Logged in as: <bdi>Admin</bdi>'",
142 )
143
144 # Ensure the generated ACL is valid
145 machine.succeed(
146 "echo 'No Hello World! for @ALL here' >> /var/lib/dokuwiki/site2.local/data/pages/acl-test.txt",
147 "curl -sSL 'http://site2.local/doku.php?id=acl-test' | grep 'Permission Denied'"
148 )
149
150 with subtest("Customizing Dokuwiki"):
151 machine.succeed(
152 "echo 'r13y is awesome!' >> /var/lib/dokuwiki/site2.local/data/pages/acronyms-test.txt",
153 "curl -sSfL 'http://site2.local/doku.php?id=acronyms-test' | grep '<abbr title=\"reproducibility\">r13y</abbr>'",
154 )
155
156 # Testing if plugins (a) be correctly loaded and (b) configuration to enable them works
157 machine.succeed(
158 "echo '~~INFO:syntaxplugins~~' >> /var/lib/dokuwiki/site2.local/data/pages/plugin-list.txt",
159 "curl -sSfL 'http://site2.local/doku.php?id=plugin-list' | grep 'plugin:icalevents'",
160 "curl -sSfL 'http://site2.local/doku.php?id=plugin-list' | (! grep 'plugin:tag')",
161 )
162
163 # Test if theme is applied and working correctly (no weird relative PHP import errors)
164 machine.succeed(
165 "curl -sSfL 'http://site1.local/doku.php' | grep 'bootstrap3/images/logo.png'",
166 "curl -sSfL 'http://site1.local/lib/exe/css.php' | grep 'bootstrap3'",
167 "curl -sSfL 'http://site1.local/lib/tpl/bootstrap3/css.php'",
168 )
169
170
171 # Just to ensure both Webserver configurations are consistent in allowing that
172 with subtest("Rewriting"):
173 machine.succeed(
174 "echo 'Hello, NixOS!' >> /var/lib/dokuwiki/site1.local/data/pages/rewrite-test.txt",
175 "curl -sSfL http://site1.local/rewrite-test | grep 'Hello, NixOS!'",
176 )
177 '';
178}