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-31 17:49:44 +01:00
|
|
|
recurrence = mkOption {
|
2021-11-01 09:20:42 +01:00
|
|
|
type = enum [ "on" "off" ];
|
2021-10-31 17:49:44 +01:00
|
|
|
default = "off";
|
|
|
|
};
|
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;
|
|
|
|
};
|
2021-11-01 09:20:42 +01:00
|
|
|
credentials = mkOption {
|
2021-10-26 05:14:15 +02:00
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
keyFile = mkOption {
|
|
|
|
type = path;
|
|
|
|
};
|
|
|
|
server = mkOption {
|
|
|
|
type = str;
|
|
|
|
};
|
2022-02-19 05:29:06 +01:00
|
|
|
tagLimitInTitle = mkOption {
|
|
|
|
type = int;
|
|
|
|
default = 10;
|
|
|
|
description = "tag limit for title, TagsInTitle must be enabled for this to work";
|
|
|
|
};
|
|
|
|
tagsInTitle = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = true;
|
|
|
|
description = "should tags be used for titles? (see tagLimitInTitle to limit the amount of tags)";
|
|
|
|
};
|
2021-10-26 05:14:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2022-01-15 09:32:59 +01:00
|
|
|
|
|
|
|
users.users.${name} = {
|
|
|
|
isSystemUser = true;
|
|
|
|
home = "/var/lib/${name}";
|
|
|
|
group = name;
|
|
|
|
};
|
|
|
|
users.groups.${name} = { };
|
|
|
|
|
2021-10-26 05:14:15 +02:00
|
|
|
systemd.services.taskwarrior-pushover = {
|
|
|
|
enable = true;
|
2021-10-26 06:44:32 +02:00
|
|
|
serviceConfig = {
|
2022-01-15 09:32:59 +01:00
|
|
|
User = name;
|
2021-10-26 06:44:32 +02:00
|
|
|
StateDirectory = name;
|
|
|
|
};
|
2021-11-01 09:20:42 +01:00
|
|
|
script =
|
|
|
|
let
|
|
|
|
taskwarriorCommand = pkgs.writers.writeDash "taskwarrior-push" ''
|
|
|
|
${pkgs.taskwarrior}/bin/task \
|
|
|
|
rc:/var/lib/${name}/.taskrc \
|
|
|
|
rc.data.location=/var/lib/${name}/${cfg.dataDir} \
|
2022-01-15 09:32:59 +01:00
|
|
|
rc.recurrence=${cfg.recurrence} \
|
2021-11-01 09:20:42 +01: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} \
|
|
|
|
"$@"
|
|
|
|
'';
|
2022-02-19 05:29:06 +01:00
|
|
|
# tags as title
|
|
|
|
title =
|
|
|
|
if (cfg.tagsInTitle && (cfg.tagLimitInTitle > 0))
|
|
|
|
then ''(.tags | if . == null or . == [] then "taskwarrior" else [limit(${toString cfg.tagLimitInTitle};.[])] | join(",") end)''
|
|
|
|
else ''"taskwarrior"'';
|
2021-11-01 09:20:42 +01:00
|
|
|
in
|
2021-10-26 05:14:15 +02:00
|
|
|
''
|
2021-11-01 09:20:42 +01:00
|
|
|
if [ -d /var/lib/${name}/${cfg.dataDir} ]
|
|
|
|
then
|
2022-01-15 09:32:59 +01:00
|
|
|
echo "synchronize ${cfg.dataDir}"
|
2021-11-01 09:20:42 +01:00
|
|
|
${taskwarriorCommand} sync
|
|
|
|
else
|
|
|
|
echo "initialize ${cfg.dataDir}"
|
|
|
|
${pkgs.coreutils}/bin/yes | ${taskwarriorCommand} sync init
|
|
|
|
fi
|
2021-10-26 05:14:15 +02:00
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
${taskwarriorCommand} '${cfg.query}' export \
|
|
|
|
| ${pkgs.jq}/bin/jq -r '.[] | @base64' | while read entry
|
|
|
|
do
|
|
|
|
echo $entry | base64 --decode | \
|
2022-02-19 05:29:06 +01:00
|
|
|
${pkgs.jq}/bin/jq '
|
|
|
|
{
|
2021-11-01 09:20:42 +01:00
|
|
|
"token": "'`cat ${cfg.pushoverApiTokenFile}`'",
|
|
|
|
"user": "'`cat ${cfg.pushoverUserKeyFile}`'",
|
2022-02-19 05:29:06 +01:00
|
|
|
title: ${title},
|
2021-11-01 09:20:42 +01:00
|
|
|
message: .description
|
|
|
|
}' \
|
|
|
|
| ${pkgs.curl}/bin/curl -sS -X POST -H 'Content-Type: application/json' -d @- \
|
|
|
|
"https://api.pushover.net/1/messages.json"
|
|
|
|
done
|
2021-11-04 08:25:48 +01:00
|
|
|
|
|
|
|
if [[ ${cfg.recurrence} -eq on ]]
|
|
|
|
then
|
|
|
|
${taskwarriorCommand} sync
|
|
|
|
fi
|
2021-10-26 05:14:15 +02:00
|
|
|
'';
|
|
|
|
};
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|