2019-01-27 02:34:47 +00:00
|
|
|
with import <stockholm/lib>;
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2019-01-27 15:55:47 +00:00
|
|
|
#for shared state directory
|
2019-01-27 02:34:47 +00:00
|
|
|
stateDir = config.krebs.reaktor2.r.stateDir;
|
|
|
|
|
|
|
|
generators = pkgs.reaktor2-plugins.generators;
|
|
|
|
hooks = pkgs.reaktor2-plugins.hooks;
|
|
|
|
commands = pkgs.reaktor2-plugins.commands;
|
|
|
|
|
2021-07-29 13:37:06 +00:00
|
|
|
taskRcFile = builtins.toFile "taskrc" ''
|
|
|
|
confirmation=no
|
|
|
|
'';
|
|
|
|
|
|
|
|
task = name: {
|
2020-06-23 07:53:21 +00:00
|
|
|
pattern = "^${name}-([a-z]+)(?::?\\s*(.*))?";
|
2019-01-27 15:55:47 +00:00
|
|
|
activate = "match";
|
|
|
|
command = 1;
|
|
|
|
arguments = [2];
|
2019-01-27 19:32:04 +00:00
|
|
|
env.TASKDATA = "${stateDir}/${name}";
|
2019-01-27 15:55:47 +00:00
|
|
|
commands = {
|
2019-01-27 19:32:04 +00:00
|
|
|
add.filename = pkgs.writeDash "${name}-task-add" ''
|
2021-07-29 13:37:06 +00:00
|
|
|
${pkgs.taskwarrior}/bin/task rc:${taskRcFile} add "$1"
|
2019-01-27 19:32:04 +00:00
|
|
|
'';
|
|
|
|
list.filename = pkgs.writeDash "${name}-task-list" ''
|
2021-07-29 13:37:06 +00:00
|
|
|
${pkgs.taskwarrior}/bin/task rc:${taskRcFile} export \
|
2019-01-27 19:32:04 +00:00
|
|
|
| ${pkgs.jq}/bin/jq -r '
|
|
|
|
.[] | select(.id != 0) | "\(.id) \(.description)"
|
|
|
|
'
|
|
|
|
'';
|
|
|
|
delete.filename = pkgs.writeDash "${name}-task-delete" ''
|
2021-07-29 13:37:06 +00:00
|
|
|
${pkgs.taskwarrior}/bin/task rc:${taskRcFile} delete "$1"
|
2019-01-27 19:32:04 +00:00
|
|
|
'';
|
|
|
|
done.filename = pkgs.writeDash "${name}-task-done" ''
|
2021-07-29 13:37:06 +00:00
|
|
|
${pkgs.taskwarrior}/bin/task rc:${taskRcFile} done "$1"
|
2019-01-27 19:32:04 +00:00
|
|
|
'';
|
2019-01-27 02:34:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemPlugin = {
|
|
|
|
plugin = "system";
|
|
|
|
config = {
|
|
|
|
workdir = stateDir;
|
|
|
|
hooks.JOIN = [
|
|
|
|
{
|
|
|
|
activate = "always";
|
|
|
|
command = {
|
|
|
|
filename =
|
2021-09-14 17:10:16 +00:00
|
|
|
<stockholm/krebs/5pkgs/simple/Reaktor/scripts/tell-on_join.sh>;
|
2019-01-27 02:34:47 +00:00
|
|
|
env = {
|
|
|
|
PATH = makeBinPath [
|
|
|
|
pkgs.coreutils # XXX env, touch
|
|
|
|
pkgs.jq # XXX sed
|
|
|
|
pkgs.utillinux # XXX flock
|
|
|
|
];
|
|
|
|
state_file = "${stateDir}/tell.json";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
hooks.PRIVMSG = [
|
|
|
|
{
|
2019-01-29 20:39:16 +00:00
|
|
|
pattern = "^bier bal(an(ce)?)?$";
|
2019-01-27 02:34:47 +00:00
|
|
|
activate = "match";
|
|
|
|
command = {
|
|
|
|
env = {
|
|
|
|
state_file = "${stateDir}/ledger";
|
|
|
|
};
|
2019-01-27 12:50:31 +00:00
|
|
|
filename = pkgs.writeDash "bier-balance" ''
|
2019-01-27 13:27:54 +00:00
|
|
|
${pkgs.hledger}/bin/hledger -f $state_file bal -N -O csv \
|
|
|
|
| ${pkgs.coreutils}/bin/tail +2 \
|
2019-07-15 16:22:35 +00:00
|
|
|
| ${pkgs.miller}/bin/mlr --icsv --opprint cat \
|
|
|
|
| ${pkgs.gnused}/bin/sed 's/^/the_/'
|
2019-01-27 02:34:47 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
2020-09-15 20:52:34 +00:00
|
|
|
pattern = ''^([\H-]*):?\s+([+-][1-9][0-9]*)\s+(\S+)$'';
|
2019-01-27 02:34:47 +00:00
|
|
|
activate = "match";
|
|
|
|
arguments = [1 2 3];
|
|
|
|
command = {
|
|
|
|
env = {
|
|
|
|
# TODO; get state as argument
|
|
|
|
state_file = "${stateDir}/ledger";
|
|
|
|
};
|
|
|
|
filename = pkgs.writeDash "ledger-add" ''
|
|
|
|
set -x
|
|
|
|
tonick=$1
|
|
|
|
amt=$2
|
|
|
|
unit=$3
|
|
|
|
printf '%s\n %s %d %s\n %s %d %s\n' "$(date -Id)" "$tonick" "$amt" "$unit" "$_from" "$(expr 0 - "''${amt#+}")" "$unit" >> $state_file
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
hooks.sed
|
|
|
|
(generators.command_hook {
|
2021-09-14 17:10:16 +00:00
|
|
|
inherit (commands) random-emoji nixos-version;
|
2019-01-27 02:34:47 +00:00
|
|
|
tell = {
|
|
|
|
filename =
|
2021-09-14 17:10:16 +00:00
|
|
|
<stockholm/krebs/5pkgs/simple/Reaktor/scripts/tell-on_privmsg.sh>;
|
2019-01-27 02:34:47 +00:00
|
|
|
env = {
|
|
|
|
PATH = makeBinPath [
|
|
|
|
pkgs.coreutils # XXX date, env
|
|
|
|
pkgs.jq # XXX sed
|
|
|
|
pkgs.utillinux # XXX flock
|
|
|
|
];
|
|
|
|
state_file = "${stateDir}/tell.txt";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
2019-01-27 15:55:47 +00:00
|
|
|
(task "agenda")
|
|
|
|
];
|
2019-01-27 02:34:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
2019-04-23 18:05:03 +00:00
|
|
|
users.users.reaktor2 = {
|
|
|
|
uid = genid_uint31 "reaktor2";
|
|
|
|
home = stateDir;
|
2021-06-05 12:14:56 +00:00
|
|
|
isSystemUser = true;
|
2021-07-29 13:46:34 +00:00
|
|
|
extraGroups = [ "reaktor2" ];
|
2019-04-23 18:05:03 +00:00
|
|
|
};
|
|
|
|
|
2021-07-29 13:46:34 +00:00
|
|
|
users.groups.reaktor2 = {};
|
|
|
|
|
2021-07-29 13:37:06 +00:00
|
|
|
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" ''
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Agenda</title>
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
<style>
|
|
|
|
html {
|
|
|
|
font-family: monospace;
|
|
|
|
}
|
|
|
|
|
|
|
|
dt {
|
|
|
|
float: left;
|
|
|
|
clear: left;
|
|
|
|
width: 30px;
|
|
|
|
text-align: right;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
dd {
|
|
|
|
margin: 0 0 0 40px;
|
|
|
|
padding: 0 0 0.5em 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.date {
|
|
|
|
color: grey;
|
|
|
|
font-style: italic;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<dl id="agenda"></dl>
|
|
|
|
<script>
|
|
|
|
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
|
|
const params = Object.fromEntries(urlSearchParams.entries());
|
|
|
|
|
|
|
|
if (params.hasOwnProperty("style")) {
|
2021-07-29 15:05:39 +00:00
|
|
|
const cssUrls = params["style"].split(" ").filter((x) => x.length > 0);
|
|
|
|
for (const cssUrl of cssUrls)
|
|
|
|
fetch(cssUrl)
|
|
|
|
.then((response) =>
|
|
|
|
response.text().then((css) => {
|
|
|
|
const title = document.getElementsByTagName("head")[0];
|
|
|
|
const style = document.createElement("style");
|
|
|
|
style.appendChild(document.createTextNode(css));
|
|
|
|
title.appendChild(style);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.catch(console.log);
|
2021-07-29 13:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fetch("/agenda.json")
|
|
|
|
.then((response) => {
|
|
|
|
response.json().then((agenda) => {
|
|
|
|
const dl = document.getElementById("agenda");
|
|
|
|
for (const agendaItem of agenda) {
|
|
|
|
if (agendaItem.status !== "pending") continue;
|
|
|
|
// task warrior date format to ISO
|
|
|
|
const entryDate = agendaItem.entry.replace(
|
|
|
|
/(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z/,
|
|
|
|
"$1-$2-$3T$4:$5:$6Z"
|
|
|
|
);
|
|
|
|
|
|
|
|
const dt = document.createElement("dt");
|
|
|
|
dt.className = "id";
|
|
|
|
dt.appendChild(document.createTextNode(agendaItem.id.toString()));
|
|
|
|
dl.appendChild(dt);
|
|
|
|
|
|
|
|
const spanDate = document.createElement("span");
|
|
|
|
spanDate.className = "date";
|
|
|
|
spanDate.title = new Date(entryDate).toString();
|
|
|
|
spanDate.appendChild(document.createTextNode(entryDate));
|
|
|
|
|
2021-09-28 20:41:33 +00:00
|
|
|
const link = document.createElement("a");
|
2021-09-28 21:02:50 +00:00
|
|
|
link.href = "http://wiki.r/agenda/" + encodeURIComponent(agendaItem.description.replaceAll("/", "\u29F8")); // we use big solidus instead of slash because gollum will create directories
|
2021-09-28 20:41:33 +00:00
|
|
|
link.appendChild(document.createTextNode(agendaItem.description));
|
|
|
|
|
2021-07-29 13:37:06 +00:00
|
|
|
const dd = document.createElement("dd");
|
|
|
|
dd.className = "description";
|
2021-09-28 20:41:33 +00:00
|
|
|
dd.appendChild(link);
|
2021-07-29 13:37:06 +00:00
|
|
|
dd.appendChild(document.createTextNode(" "));
|
|
|
|
dd.appendChild(spanDate);
|
|
|
|
|
|
|
|
dl.appendChild(dd);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then((data) => console.log(data));
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
''};
|
|
|
|
'';
|
|
|
|
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';
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-07-29 13:46:34 +00:00
|
|
|
systemd.services.reaktor2-r.serviceConfig.DynamicUser = mkForce false;
|
|
|
|
systemd.services.reaktor2-hackint.serviceConfig.DynamicUser = mkForce false;
|
2019-01-27 02:34:47 +00:00
|
|
|
krebs.reaktor2 = {
|
2021-05-20 08:57:27 +00:00
|
|
|
hackint = {
|
|
|
|
hostname = "irc.hackint.org";
|
|
|
|
nick = "reaktor2|krebs";
|
|
|
|
plugins = [
|
|
|
|
{
|
|
|
|
plugin = "register";
|
|
|
|
config = {
|
|
|
|
channels = [
|
|
|
|
"#krebs"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
systemPlugin
|
|
|
|
];
|
2021-05-20 10:54:30 +00:00
|
|
|
username = "reaktor2";
|
2021-05-20 08:57:27 +00:00
|
|
|
port = "6697";
|
|
|
|
};
|
2019-01-27 02:34:47 +00:00
|
|
|
r = {
|
|
|
|
nick = "reaktor2|krebs";
|
2019-01-29 20:39:16 +00:00
|
|
|
sendDelaySec = null;
|
2019-01-27 02:34:47 +00:00
|
|
|
plugins = [
|
|
|
|
{
|
|
|
|
plugin = "register";
|
|
|
|
config = {
|
|
|
|
channels = [
|
|
|
|
"#noise"
|
|
|
|
"#xxx"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
systemPlugin
|
|
|
|
];
|
2019-01-27 19:06:06 +00:00
|
|
|
username = "reaktor2";
|
2019-01-27 02:34:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|