From 907171a4417a432d2efb5a392c7a39166a31ba2c Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Mon, 18 Jul 2022 19:59:15 +0200 Subject: [PATCH] add taskwarrior-autotag to support ios --- nixos/configs/pepe/taskwarrior-pushover.nix | 57 ++++++++-- nixos/modules/default.nix | 1 + .../modules/services/taskwarrior-autotag.nix | 106 ++++++++++++++++++ 3 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 nixos/modules/services/taskwarrior-autotag.nix diff --git a/nixos/configs/pepe/taskwarrior-pushover.nix b/nixos/configs/pepe/taskwarrior-pushover.nix index e4bc405..d6c52b5 100644 --- a/nixos/configs/pepe/taskwarrior-pushover.nix +++ b/nixos/configs/pepe/taskwarrior-pushover.nix @@ -1,12 +1,28 @@ { config, lib, pkgs, ... }: { + sops.secrets.pushoverApiToken = { + owner = "taskwarrior-pushover"; + key = "pushoverApiToken"; + }; + sops.secrets.pushoverUserKey = { + owner = "taskwarrior-pushover"; + key = "pushoverUserKey"; + }; + + sops.secrets.pushoverTaskwarriorCa = { + owner = "taskwarrior-pushover"; + key = "taskwarriorCa"; + }; + sops.secrets.pushoverTaskwarriorCertificate = { + owner = "taskwarrior-pushover"; + key = "taskwarriorCertificate"; + }; + sops.secrets.pushoverTaskwarriorKey = { + owner = "taskwarrior-pushover"; + key = "taskwarriorKey"; + }; - sops.secrets.pushoverApiToken.owner = "taskwarrior-pushover"; - sops.secrets.pushoverUserKey.owner = "taskwarrior-pushover"; - sops.secrets.taskwarriorCa.owner = "taskwarrior-pushover"; - sops.secrets.taskwarriorCertificate.owner = "taskwarrior-pushover"; - sops.secrets.taskwarriorKey.owner = "taskwarrior-pushover"; services.taskwarrior-pushover = { enable = true; @@ -15,9 +31,34 @@ 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; + caFile = config.sops.secrets.pushoverTaskwarriorCa.path; + certificateFile = config.sops.secrets.pushoverTaskwarriorCertificate.path; + keyFile = config.sops.secrets.pushoverTaskwarriorKey.path; credentials = "1337/palo/ed0fdbe8-2dc3-408b-84cb-d07d363bccd2"; }; + + sops.secrets.autotagTaskwarriorCa = { + owner = "taskwarrior-autotag"; + key = "taskwarriorCa"; + }; + sops.secrets.autotagTaskwarriorCertificate = { + owner = "taskwarrior-autotag"; + key = "taskwarriorCertificate"; + }; + sops.secrets.autotagTaskwarriorKey = { + owner = "taskwarrior-autotag"; + key = "taskwarriorKey"; + }; + + + services.taskwarrior-autotag = { + enable = true; + onCalendar = "hourly"; + server = "taskd.ingolf-wagner.de:53589"; + caFile = config.sops.secrets.autotagTaskwarriorCa.path; + certificateFile = config.sops.secrets.autotagTaskwarriorCertificate.path; + keyFile = config.sops.secrets.autotagTaskwarriorKey.path; + credentials = "1337/palo/ed0fdbe8-2dc3-408b-84cb-d07d363bccd2"; + }; + } diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix index 1a90107..a13551e 100644 --- a/nixos/modules/default.nix +++ b/nixos/modules/default.nix @@ -11,6 +11,7 @@ ./services/sshd.nix ./services/videoencoder.nix ./services/taskwarrior-pushover.nix + ./services/taskwarrior-autotag.nix ./programs/browser.nix ./programs/citate.nix diff --git a/nixos/modules/services/taskwarrior-autotag.nix b/nixos/modules/services/taskwarrior-autotag.nix new file mode 100644 index 0000000..4b9deac --- /dev/null +++ b/nixos/modules/services/taskwarrior-autotag.nix @@ -0,0 +1,106 @@ +{ 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.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" ]; + }; + }; + +}