From 41a49361440522529f9a74e5fd37dc3a5c4f2bd0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= <kieran.meinhardt@gmail.com>
Date: Tue, 9 Jul 2019 20:29:41 +0200
Subject: [PATCH 1/2] urlwatch: optionalise custom sendmail

---
 krebs/3modules/urlwatch.nix | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/krebs/3modules/urlwatch.nix b/krebs/3modules/urlwatch.nix
index 0cec1a2d3..3213080de 100644
--- a/krebs/3modules/urlwatch.nix
+++ b/krebs/3modules/urlwatch.nix
@@ -17,6 +17,8 @@ let
   api = {
     enable = mkEnableOption "krebs.urlwatch";
 
+    customSendmail.enable = mkEnableOption "krebs.urlwatch.customSendmail";
+
     dataDir = mkOption {
       type = types.str;
       default = "/var/lib/urlwatch";
@@ -158,19 +160,21 @@ let
               --urls=${shell.escape urlsFile} \
             > changes || :
 
-          if test -s changes; then
-            {
-              echo Date: $(date -R)
-              echo From: ${shell.escape cfg.from}
-              echo Subject: $(
-                sed -n 's/^\(CHANGED\|ERROR\|NEW\): //p' changes \
-                  | tr '\n' ' '
-              )
-              echo To: ${shell.escape cfg.mailto}
-              echo
-              cat changes
-            } | /run/wrappers/bin/sendmail -t
-          fi
+          ${optionalString cfg.customSendmail.enable /* sh */ ''
+            if test -s changes; then
+              {
+                echo Date: $(date -R)
+                echo From: ${shell.escape cfg.from}
+                echo Subject: $(
+                  sed -n 's/^\(CHANGED\|ERROR\|NEW\): //p' changes \
+                    | tr '\n' ' '
+                )
+                echo To: ${shell.escape cfg.mailto}
+                echo
+                cat changes
+              } | /run/wrappers/bin/sendmail -t
+            fi
+          ''}
         '';
       };
     };

From b9ab8446354378719dfa546108d4e96f7852d3d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= <kieran.meinhardt@gmail.com>
Date: Tue, 9 Jul 2019 20:30:05 +0200
Subject: [PATCH 2/2] urlwatch: add telegram reporting options

---
 krebs/3modules/urlwatch.nix | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/krebs/3modules/urlwatch.nix b/krebs/3modules/urlwatch.nix
index 3213080de..3c9ff7709 100644
--- a/krebs/3modules/urlwatch.nix
+++ b/krebs/3modules/urlwatch.nix
@@ -56,6 +56,15 @@ let
         The format is described in systemd.time(7), CALENDAR EVENTS.
       '';
     };
+    telegram = {
+      enable = mkEnableOption "krebs.urlwatch.telegram" // { default = false; };
+      botToken = mkOption {
+        type = types.str;
+      };
+      chatId = mkOption {
+        type = types.listOf types.str;
+      };
+    };
     urls = mkOption {
       type = with types; listOf (either str subtypes.job);
       default = [];
@@ -112,6 +121,11 @@ let
         color = true;
         enabled = true;
       };
+      ${if cfg.telegram.enable then "telegram" else null} = {
+        enabled = cfg.telegram.enable;
+        bot_token = cfg.telegram.botToken;
+        chat_id = cfg.telegram.chatId;
+      };
       text = {
         details = true;
         footer = true;