107 lines
2.8 KiB
Nix
107 lines
2.8 KiB
Nix
{ 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} \
|
|
rc.recurrence.confirmation=no \
|
|
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}'";
|
|
unset_tag_query = "'! ${cfg.query}'";
|
|
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" ];
|
|
};
|
|
};
|
|
|
|
}
|