nixos-config/modules/taskwarrior-autotag.nix

108 lines
2.8 KiB
Nix
Raw Normal View History

2022-07-18 19:59:15 +02:00
{ config, lib, pkgs, ... }:
with lib;
with types;
let
cfg = config.services.taskwarrior-autotag;
name = "taskwarrior-autotag";
in
{
options.services.taskwarrior-autotag = {
enable = mkEnableOption "taskwarrior autotag notification service";
onCalendar = mkOption {
type = str;
default = "4:00:00";
};
recurrence = mkOption {
type = enum [ "on" "off" ];
default = "off";
};
query = mkOption {
type = str;
default = "( +ACTIVE or +DUETODAY or +TODAY or +OVERDUE )";
};
dataDir = mkOption {
type = str;
default = "tasks";
};
tag_name = mkOption {
type = str;
default = "yolo";
description = "tag do be set to the querried tasks.";
};
caFile = mkOption {
type = path;
};
certificateFile = mkOption {
type = path;
};
credentials = mkOption {
type = str;
};
keyFile = mkOption {
type = path;
};
server = mkOption {
type = str;
};
};
config = mkIf cfg.enable {
users.users.${name} = {
isSystemUser = true;
home = "/var/lib/${name}";
group = name;
};
users.groups.${name} = { };
systemd.services.taskwarrior-autotag = {
enable = true;
serviceConfig = {
User = name;
StateDirectory = name;
};
script =
let
taskwarriorCommand = pkgs.writers.writeDash "taskwarrior-autotag" ''
${pkgs.taskwarrior}/bin/task \
rc:/var/lib/${name}/.taskrc \
rc.data.location=/var/lib/${name}/${cfg.dataDir} \
rc.recurrence=${cfg.recurrence} \
2022-07-23 13:22:23 +02:00
rc.recurrence.confirmation=no \
2022-07-18 19:59: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} \
"$@"
'';
set_tag_query = "status:pending '${cfg.query}'";
2022-07-29 11:48:58 +02:00
unset_tag_query = "'! ${cfg.query}'";
2022-07-18 19:59:15 +02:00
yes = "${pkgs.coreutils}/bin/yes";
in
''
if [ -d /var/lib/${name}/${cfg.dataDir} ]
then
echo "synchronize ${cfg.dataDir}"
${taskwarriorCommand} sync
else
echo "initialize ${cfg.dataDir}"
${pkgs.coreutils}/bin/yes | ${taskwarriorCommand} sync init
fi
# todo continue
${yes} | ${taskwarriorCommand} ${unset_tag_query} mod -${cfg.tag_name}
${yes} | ${taskwarriorCommand} ${set_tag_query} mod +${cfg.tag_name}
${taskwarriorCommand} sync
'';
};
systemd.timers.taskwarrior-autotag = {
enable = true;
timerConfig.OnCalendar = cfg.onCalendar;
wantedBy = [ "multi-user.target" ];
};
};
}