From 3acf05147a778b99b3570513d49efafeda64b664 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Tue, 26 Oct 2021 05:14:15 +0200 Subject: [PATCH] add taskwarrior-pushover module --- flake.lock | 8 +- nixos/configs/pepe/configuration.nix | 1 + nixos/configs/pepe/taskwarrior-pushover.nix | 20 +++++ nixos/modules/default.nix | 1 + .../modules/services/taskwarrior-pushover.nix | 88 +++++++++++++++++++ 5 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 nixos/configs/pepe/taskwarrior-pushover.nix create mode 100644 nixos/modules/services/taskwarrior-pushover.nix diff --git a/flake.lock b/flake.lock index a3175c2..fc4fb8f 100644 --- a/flake.lock +++ b/flake.lock @@ -38,11 +38,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1633422542, - "narHash": "sha256-JYz2PmVogNRO8DhcvXzL/QhZzboTspJz2YSRlnAj8aM=", + "lastModified": 1635070614, + "narHash": "sha256-eRup9WsvSIhsRrSlNugPcQ7gfGOsbk3d4izufwVlz1Q=", "owner": "nixos", "repo": "nixpkgs", - "rev": "aff647e2704fa1223994604887bb78276dc57083", + "rev": "3b1789322fcbcb5cf51228d732752714f1bf77da", "type": "github" }, "original": { @@ -62,7 +62,7 @@ "secrets": { "flake": false, "locked": { - "narHash": "sha256-1myorrO1qwgIHPz2UkU45qZp+X4RdQgJpay93z1VNCM=", + "narHash": "sha256-7kNQHKkMjjTBPgRzHh34KqbcorqgEyGcu8UQfFxEvb8=", "path": "/home/palo/dev/secrets", "type": "path" }, diff --git a/nixos/configs/pepe/configuration.nix b/nixos/configs/pepe/configuration.nix index 20b9f41..e42678f 100644 --- a/nixos/configs/pepe/configuration.nix +++ b/nixos/configs/pepe/configuration.nix @@ -15,6 +15,7 @@ ./borg.nix ./mpd.nix ./grocy.nix + ./taskwarrior-pushover.nix ]; diff --git a/nixos/configs/pepe/taskwarrior-pushover.nix b/nixos/configs/pepe/taskwarrior-pushover.nix new file mode 100644 index 0000000..6d3af65 --- /dev/null +++ b/nixos/configs/pepe/taskwarrior-pushover.nix @@ -0,0 +1,20 @@ +{ config, lib, pkgs, ... }: + +{ + sops.secrets.pushoverApiToken = {}; + sops.secrets.pushoverUserKey = {}; + sops.secrets.taskwarriorCa = {}; + sops.secrets.taskwarriorCertificate = {}; + sops.secrets.taskwarriorKey = {}; + + services.taskwarrior-pushover = { + enable = true; + 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; + credentials= "1337/palo/ed0fdbe8-2dc3-408b-84cb-d07d363bccd2"; + }; +} diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix index 87f8feb..1a90107 100644 --- a/nixos/modules/default.nix +++ b/nixos/modules/default.nix @@ -10,6 +10,7 @@ ./services/samba-share.nix ./services/sshd.nix ./services/videoencoder.nix + ./services/taskwarrior-pushover.nix ./programs/browser.nix ./programs/citate.nix diff --git a/nixos/modules/services/taskwarrior-pushover.nix b/nixos/modules/services/taskwarrior-pushover.nix new file mode 100644 index 0000000..bc7df68 --- /dev/null +++ b/nixos/modules/services/taskwarrior-pushover.nix @@ -0,0 +1,88 @@ +{ config, lib, pkgs, ... }: + +with lib; +with types; +let + cfg = config.services.taskwarrior-pushover; +in +{ + options.services.taskwarrior-pushover = { + enable = mkEnableOption "taskwarrior pushover notification service"; + pushoverApiTokenFile = mkOption { + type = path; + }; + pushoverUserKeyFile = mkOption { + type = path; + }; + query = mkOption { + type = str; + default = "+PENDING and ( +ACTIVE and +DUETODAY or +TODAY or +OVERDUE )"; + }; + dataDir = mkOption { + type = str; + default = "/var/lib/taskwarrior-pushover"; + }; + 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; + #serviceConfig = { + # DynamicUser = true; + #}; + script = let + taskwarriorCommand = pkgs.writers.writeDash "taskwarrior-push" '' + ${pkgs.taskwarrior}/bin/task \ + rc.recurrence=off \ + rc.data.location=${cfg.dataDir} \ + 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 + '' + if [ -d ${cfg.dataDir} ] + then + echo "syncronize ${cfg.dataDir}" + ${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 + ''; + }; + }; + +}