nixos/tiddlywiki: init

Service that runs TiddlyWiki nodejs server
This commit is contained in:
Nazarii Bardiuk 2019-04-29 21:46:00 +01:00
parent c7a4a0c852
commit 976928daa2
No known key found for this signature in database
GPG Key ID: C9C1904D44CDCDA1
4 changed files with 121 additions and 0 deletions

View File

@ -469,6 +469,7 @@
./services/misc/synergy.nix
./services/misc/sysprof.nix
./services/misc/taskserver
./services/misc/tiddlywiki.nix
./services/misc/tzupdate.nix
./services/misc/uhub.nix
./services/misc/weechat.nix

View File

@ -0,0 +1,52 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.tiddlywiki;
listenParams = concatStrings (mapAttrsToList (n: v: " '${n}=${toString v}' ") cfg.listenOptions);
exe = "${pkgs.nodePackages.tiddlywiki}/lib/node_modules/.bin/tiddlywiki";
name = "tiddlywiki";
dataDir = "/var/lib/" + name;
in {
options.services.tiddlywiki = {
enable = mkEnableOption "TiddlyWiki nodejs server";
listenOptions = mkOption {
type = types.attrs;
default = {};
example = {
credentials = "../credentials.csv";
readers="(authenticated)";
port = 3456;
};
description = ''
Parameters passed to <literal>--listen</literal> command.
Refer to <link xlink:href="https://tiddlywiki.com/#WebServer"/>
for details on supported values.
'';
};
};
config = mkIf cfg.enable {
systemd = {
services.tiddlywiki = {
description = "TiddlyWiki nodejs server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
Restart = "on-failure";
DynamicUser = true;
StateDirectory = name;
ExecStartPre = "-${exe} ${dataDir} --init server";
ExecStart = "${exe} ${dataDir} --listen ${listenParams}";
};
};
};
};
}

View File

@ -245,6 +245,7 @@ in
pdns-recursor = handleTest ./pdns-recursor.nix {};
taskserver = handleTest ./taskserver.nix {};
telegraf = handleTest ./telegraf.nix {};
tiddlywiki = handleTest ./tiddlywiki.nix {};
tinydns = handleTest ./tinydns.nix {};
tomcat = handleTest ./tomcat.nix {};
tor = handleTest ./tor.nix {};

View File

@ -0,0 +1,67 @@
import ./make-test.nix ({ ... }: {
name = "tiddlywiki";
nodes = {
default = {
services.tiddlywiki.enable = true;
};
configured = {
boot.postBootCommands = ''
echo "username,password
somelogin,somesecret" > /var/lib/wikiusers.csv
'';
services.tiddlywiki = {
enable = true;
listenOptions = {
port = 3000;
credentials="../wikiusers.csv";
readers="(authenticated)";
};
};
};
};
testScript = ''
startAll;
subtest "by default works without configuration", sub {
$default->waitForUnit("tiddlywiki.service");
};
subtest "by default available on port 8080 without auth", sub {
$default->waitForUnit("tiddlywiki.service");
$default->waitForOpenPort(8080);
$default->succeed("curl --fail 127.0.0.1:8080");
};
subtest "by default creates empty wiki", sub {
$default->succeed("test -f /var/lib/tiddlywiki/tiddlywiki.info");
};
subtest "configured on port 3000 with basic auth", sub {
$configured->waitForUnit("tiddlywiki.service");
$configured->waitForOpenPort(3000);
$configured->fail("curl --fail 127.0.0.1:3000");
$configured->succeed("curl --fail 127.0.0.1:3000 --user somelogin:somesecret");
};
subtest "configured with different wikifolder", sub {
$configured->succeed("test -f /var/lib/tiddlywiki/tiddlywiki.info");
};
subtest "restart preserves changes", sub {
# given running wiki
$default->waitForUnit("tiddlywiki.service");
# with some changes
$default->succeed("curl --fail --request PUT --header 'X-Requested-With:TiddlyWiki' --data '{ \"title\": \"title\", \"text\": \"content\" }' --url 127.0.0.1:8080/recipes/default/tiddlers/somepage ");
$default->succeed("sleep 2"); # server syncs to filesystem on timer
# when wiki is cycled
$default->systemctl("restart tiddlywiki.service");
$default->waitForUnit("tiddlywiki.service");
$default->waitForOpenPort(8080);
# the change is preserved
$default->succeed("curl --fail 127.0.0.1:8080/recipes/default/tiddlers/somepage");
};
'';
})