stockholm/lass/2configs/fysiirc.nix

74 lines
1.9 KiB
Nix
Raw Normal View History

2022-01-28 15:15:30 +00:00
{ config, lib, pkgs, ... }: let
format-github-message = pkgs.writeDashBin "format-github-message" ''
set -xefu
export PATH=${lib.makeBinPath [
pkgs.jq
]}
INPUT=$(jq -c .)
if $(echo "$INPUT" | jq 'has("issue") or has("pull_request")'); then
${write_to_irc} "$(echo "$INPUT" | jq -r '
"\(.action): " +
"[\(.issue.title // .pull_request.title)] " +
"\(.comment.html_url // .issue.html_url // .pull_request.html_url) " +
"by \(.comment.user.login // .issue.user.login // .pull_request.user.login)"
')"
fi
'';
write_to_irc = pkgs.writeDash "write_to_irc" ''
${pkgs.curl}/bin/curl -fsSv http://localhost:44001 \
-H content-type:application/json \
-d "$(${pkgs.jq}/bin/jq -n \
--arg text "$1" '{
command:"PRIVMSG",
params:["#fysi",$text]
}'
)"
'';
in {
2022-01-26 15:41:59 +00:00
krebs.iptables.tables.filter.INPUT.rules = [
{ predicate = "-p tcp --dport 44002"; target = "ACCEPT"; }
];
krebs.reaktor2.fysiweb-github = {
hostname = "irc.libera.chat";
port = "6697";
useTLS = true;
nick = "fysiweb-github";
API.listen = "inet://127.0.0.1:44001";
plugins = [
{
plugin = "register";
config = {
channels = [
"#fysi"
];
};
}
];
};
krebs.htgen.fysiweb-github = {
port = 44002;
user = {
name = "reaktor2-fysiweb-github";
};
script = ''. ${pkgs.writeDash "github-irc" ''
2022-01-28 15:15:30 +00:00
set -efu
2022-01-26 15:41:59 +00:00
case "$Method $Request_URI" in
"POST /")
payload=$(head -c "$req_content_length" \
| sed 's/+/ /g;s/%\(..\)/\\x\1/g;' \
| xargs -0 echo -e \
)
2022-01-28 15:15:30 +00:00
echo "$payload" | ${format-github-message}/bin/format-github-message
2022-01-26 15:41:59 +00:00
printf 'HTTP/1.1 200 OK\r\n'
printf 'Connection: close\r\n'
printf '\r\n'
exit
;;
esac
''}'';
};
}