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