about summary refs log tree commit diff
path: root/modules/nixos/ntfy.nix
diff options
context:
space:
mode:
authorAzat Bahawi <azat@bahawi.net>2023-04-01 04:39:59 +0300
committerAzat Bahawi <azat@bahawi.net>2023-04-01 04:39:59 +0300
commitf4145939712b0046e5d57906d4b157b8a150614d (patch)
tree3c8d24db6410692e0fa59570ff698d446ae5a96e /modules/nixos/ntfy.nix
parent2023-03-23 (diff)
2023-04-01
Diffstat (limited to '')
-rw-r--r--modules/nixos/ntfy.nix31
1 files changed, 28 insertions, 3 deletions
diff --git a/modules/nixos/ntfy.nix b/modules/nixos/ntfy.nix
index 80b6247..f8510d5 100644
--- a/modules/nixos/ntfy.nix
+++ b/modules/nixos/ntfy.nix
@@ -1,6 +1,7 @@
 {
   config,
   lib,
+  this,
   ...
 }:
 with lib; let
@@ -20,6 +21,22 @@ in {
       type = with types; str;
       default = "ntfy.${config.networking.domain}";
     };
+
+    prometheus = {
+      enable = mkEnableOption "Prometheus exporter." // {default = true;};
+
+      address = mkOption {
+        description = "Address.";
+        type = with types; str;
+        default = this.wireguard.ipv4.address;
+      };
+
+      port = mkOption {
+        description = "Port.";
+        type = with types; port;
+        default = 9289;
+      };
+    };
   };
 
   config = mkIf cfg.enable {
@@ -27,9 +44,14 @@ in {
       enable = true;
       upstreams.ntfy.servers.${config.services.ntfy-sh.settings.listen-http} = {};
       virtualHosts.${cfg.domain} = {
-        locations."/" = {
-          proxyPass = "http://ntfy";
-          proxyWebsockets = true;
+        locations = {
+          "/" = {
+            proxyPass = "http://ntfy";
+            proxyWebsockets = true;
+          };
+          "/metrics".extraConfig = ''
+            deny all;
+          '';
         };
         extraConfig = nginxInternalOnly;
       };
@@ -44,6 +66,9 @@ in {
         behind-proxy = true;
         attachment-cache-dir = "/var/cache/ntfy/attachments";
         auth-file = "/var/lib/ntfy/user.db";
+        enable-metrics = cfg.prometheus.enable;
+        metrics-listen-http = with cfg.prometheus;
+          optionalString cfg.prometheus.enable "${address}:${toString port}";
       };
     };
 

Consider giving Nix/NixOS a try! <3