2021-10-26 05:14:15 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
with types;
|
|
|
|
let
|
|
|
|
cfg = config.services.taskwarrior-pushover;
|
2021-10-26 06:44:32 +02:00
|
|
|
name = "taskwarrior-pushover";
|
2021-10-26 05:14:15 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.taskwarrior-pushover = {
|
|
|
|
enable = mkEnableOption "taskwarrior pushover notification service";
|
2021-10-26 06:44:32 +02:00
|
|
|
onCalendar = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "4:00:00";
|
|
|
|
};
|
2021-10-26 05:14:15 +02:00
|
|
|
pushoverApiTokenFile = mkOption {
|
|
|
|
type = path;
|
|
|
|
};
|
|
|
|
pushoverUserKeyFile = mkOption {
|
|
|
|
type = path;
|
|
|
|
};
|
|
|
|
query = mkOption {
|
|
|
|
type = str;
|
2021-10-26 07:06:52 +02:00
|
|
|
default = "+PENDING and ( +ACTIVE or +DUETODAY or +TODAY or +OVERDUE )";
|
2021-10-26 05:14:15 +02:00
|
|
|
};
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = str;
|
2021-10-26 06:44:32 +02:00
|
|
|
default = "tasks";
|
2021-10-26 05:14:15 +02:00
|
|
|
};
|
|
|
|
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;
|
2021-10-26 06:44:32 +02:00
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = name;
|
|
|
|
};
|
2021-10-26 05:14:15 +02:00
|
|
|
script = let
|
|
|
|
taskwarriorCommand = pkgs.writers.writeDash "taskwarrior-push" ''
|
|
|
|
${pkgs.taskwarrior}/bin/task \
|
|
|
|
rc.recurrence=off \
|
2021-10-26 06:44:32 +02:00
|
|
|
rc:/var/lib/${name}/.taskrc \
|
|
|
|
rc.data.location=/var/lib/${name}/${cfg.dataDir} \
|
2021-10-26 05:14:15 +02:00
|
|
|
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
|
|
|
|
''
|
2021-10-26 07:06:52 +02:00
|
|
|
if [ -d /var/lib/${name}/${cfg.dataDir} ]
|
2021-10-26 05:14:15 +02:00
|
|
|
then
|
2021-10-26 18:56:13 +02:00
|
|
|
echo "synchronize {cfg.dataDir}"
|
2021-10-26 05:14:15 +02:00
|
|
|
${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
|
|
|
|
'';
|
|
|
|
};
|
2021-10-26 06:44:32 +02:00
|
|
|
systemd.timers.taskwarrior-pushover = {
|
|
|
|
enable = true;
|
|
|
|
timerConfig.OnCalendar = cfg.onCalendar;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
2021-10-26 05:14:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|