From a59ca4ac80248585facd8cc43d0a8b8d43e3735d Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 29 Jul 2021 15:37:06 +0200 Subject: [PATCH] reaktor2: add agenda.r webinterface --- krebs/2configs/reaktor2.nix | 141 +++++++++++++++++++++++++++++++++--- 1 file changed, 132 insertions(+), 9 deletions(-) diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index 14e0a3d7a..2fb7a54e8 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -9,11 +9,11 @@ let hooks = pkgs.reaktor2-plugins.hooks; commands = pkgs.reaktor2-plugins.commands; - task = name: let - rcFile = builtins.toFile "taskrc" '' - confirmation=no - ''; - in { + taskRcFile = builtins.toFile "taskrc" '' + confirmation=no + ''; + + task = name: { pattern = "^${name}-([a-z]+)(?::?\\s*(.*))?"; activate = "match"; command = 1; @@ -21,19 +21,19 @@ let env.TASKDATA = "${stateDir}/${name}"; commands = { add.filename = pkgs.writeDash "${name}-task-add" '' - ${pkgs.taskwarrior}/bin/task rc:${rcFile} add "$1" + ${pkgs.taskwarrior}/bin/task rc:${taskRcFile} add "$1" ''; list.filename = pkgs.writeDash "${name}-task-list" '' - ${pkgs.taskwarrior}/bin/task rc:${rcFile} export \ + ${pkgs.taskwarrior}/bin/task rc:${taskRcFile} export \ | ${pkgs.jq}/bin/jq -r ' .[] | select(.id != 0) | "\(.id) \(.description)" ' ''; delete.filename = pkgs.writeDash "${name}-task-delete" '' - ${pkgs.taskwarrior}/bin/task rc:${rcFile} delete "$1" + ${pkgs.taskwarrior}/bin/task rc:${taskRcFile} delete "$1" ''; done.filename = pkgs.writeDash "${name}-task-done" '' - ${pkgs.taskwarrior}/bin/task rc:${rcFile} done "$1" + ${pkgs.taskwarrior}/bin/task rc:${taskRcFile} done "$1" ''; }; }; @@ -122,6 +122,129 @@ in { isSystemUser = true; }; + systemd.services.htgen-agenda.serviceConfig.StateDirectory = "reaktor2"; + krebs.htgen.agenda = { + port = 8009; + user = { + name = "reaktor2"; + home = stateDir; + }; + script = ''. ${pkgs.writeDash "agenda" '' + echo "$Method $Request_URI" >&2 + case "$Method" in + "GET") + printf 'HTTP/1.1 200 OK\r\n' + printf 'Connection: close\r\n' + printf '\r\n' + TASKDATA=/var/lib/reaktor2/agenda ${pkgs.taskwarrior}/bin/task rc:${taskRcFile} export + exit + ;; + esac + ''}''; + }; + + services.nginx = { + virtualHosts."agenda.r" = { + locations."= /index.html".extraConfig = '' + alias ${pkgs.writeText "agenda.html" '' + + + + Agenda + + + + + +
+ + + + ''}; + ''; + locations."/agenda.json".extraConfig = '' + proxy_set_header Host $host; + proxy_pass http://localhost:8009; + ''; + extraConfig = '' + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + ''; + }; + }; + krebs.reaktor2 = { hackint = { hostname = "irc.hackint.org";