add taskwarrior-pushover module

This commit is contained in:
Ingolf Wagner 2021-10-26 05:14:15 +02:00
parent fe2b8e501e
commit 3acf05147a
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
5 changed files with 114 additions and 4 deletions

View file

@ -38,11 +38,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1633422542, "lastModified": 1635070614,
"narHash": "sha256-JYz2PmVogNRO8DhcvXzL/QhZzboTspJz2YSRlnAj8aM=", "narHash": "sha256-eRup9WsvSIhsRrSlNugPcQ7gfGOsbk3d4izufwVlz1Q=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "aff647e2704fa1223994604887bb78276dc57083", "rev": "3b1789322fcbcb5cf51228d732752714f1bf77da",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -62,7 +62,7 @@
"secrets": { "secrets": {
"flake": false, "flake": false,
"locked": { "locked": {
"narHash": "sha256-1myorrO1qwgIHPz2UkU45qZp+X4RdQgJpay93z1VNCM=", "narHash": "sha256-7kNQHKkMjjTBPgRzHh34KqbcorqgEyGcu8UQfFxEvb8=",
"path": "/home/palo/dev/secrets", "path": "/home/palo/dev/secrets",
"type": "path" "type": "path"
}, },

View file

@ -15,6 +15,7 @@
./borg.nix ./borg.nix
./mpd.nix ./mpd.nix
./grocy.nix ./grocy.nix
./taskwarrior-pushover.nix
]; ];

View file

@ -0,0 +1,20 @@
{ config, lib, pkgs, ... }:
{
sops.secrets.pushoverApiToken = {};
sops.secrets.pushoverUserKey = {};
sops.secrets.taskwarriorCa = {};
sops.secrets.taskwarriorCertificate = {};
sops.secrets.taskwarriorKey = {};
services.taskwarrior-pushover = {
enable = true;
server = "taskd.ingolf-wagner.de:53589";
pushoverApiTokenFile = config.sops.secrets.pushoverApiToken.path;
pushoverUserKeyFile = config.sops.secrets.pushoverUserKey.path;
caFile = config.sops.secrets.taskwarriorCa.path;
certificateFile = config.sops.secrets.taskwarriorCertificate.path;
keyFile = config.sops.secrets.taskwarriorKey.path;
credentials= "1337/palo/ed0fdbe8-2dc3-408b-84cb-d07d363bccd2";
};
}

View file

@ -10,6 +10,7 @@
./services/samba-share.nix ./services/samba-share.nix
./services/sshd.nix ./services/sshd.nix
./services/videoencoder.nix ./services/videoencoder.nix
./services/taskwarrior-pushover.nix
./programs/browser.nix ./programs/browser.nix
./programs/citate.nix ./programs/citate.nix

View file

@ -0,0 +1,88 @@
{ config, lib, pkgs, ... }:
with lib;
with types;
let
cfg = config.services.taskwarrior-pushover;
in
{
options.services.taskwarrior-pushover = {
enable = mkEnableOption "taskwarrior pushover notification service";
pushoverApiTokenFile = mkOption {
type = path;
};
pushoverUserKeyFile = mkOption {
type = path;
};
query = mkOption {
type = str;
default = "+PENDING and ( +ACTIVE and +DUETODAY or +TODAY or +OVERDUE )";
};
dataDir = mkOption {
type = str;
default = "/var/lib/taskwarrior-pushover";
};
caFile = mkOption {
type = path;
};
certificateFile = mkOption {
type = path;
};
credentials= mkOption {
type = str;
};
keyFile = mkOption {
type = path;
};
server = mkOption {
type = str;
};
};
config = mkIf cfg.enable {
systemd.services.taskwarrior-pushover = {
enable = true;
#serviceConfig = {
# DynamicUser = true;
#};
script = let
taskwarriorCommand = pkgs.writers.writeDash "taskwarrior-push" ''
${pkgs.taskwarrior}/bin/task \
rc.recurrence=off \
rc.data.location=${cfg.dataDir} \
rc.taskd.ca=${cfg.caFile} \
rc.taskd.certificate=${cfg.certificateFile} \
rc.taskd.credentials="${cfg.credentials}" \
rc.taskd.key=${cfg.keyFile} \
rc.taskd.server=${cfg.server} \
"$@"
'';
in
''
if [ -d ${cfg.dataDir} ]
then
echo "syncronize ${cfg.dataDir}"
${taskwarriorCommand} sync
else
echo "initialize ${cfg.dataDir}"
${pkgs.coreutils}/bin/yes | ${taskwarriorCommand} sync init
fi
${taskwarriorCommand} '${cfg.query}' export \
| ${pkgs.jq}/bin/jq -r '.[] | @base64' | while read entry
do
echo $entry | base64 --decode | \
${pkgs.jq}/bin/jq '{
"token": "'`cat ${cfg.pushoverApiTokenFile}`'",
"user": "'`cat ${cfg.pushoverUserKeyFile}`'",
"titel": "taskwarrior",
message: .description
}' \
| ${pkgs.curl}/bin/curl -sS -X POST -H 'Content-Type: application/json' -d @- \
"https://api.pushover.net/1/messages.json"
done
'';
};
};
}