From 57ac788c6f4d8c7f57377b703848fc055cf44c70 Mon Sep 17 00:00:00 2001 From: pazpi Date: Fri, 29 Nov 2024 16:15:54 +0100 Subject: [PATCH] feat: Add Uptime Kuma monitoring service --- modules/monitoring/default.nix | 1 + modules/monitoring/uptime-kuma.nix | 60 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 modules/monitoring/uptime-kuma.nix diff --git a/modules/monitoring/default.nix b/modules/monitoring/default.nix index 71469f4..3e2e1d1 100644 --- a/modules/monitoring/default.nix +++ b/modules/monitoring/default.nix @@ -3,5 +3,6 @@ ./grafana.nix ./loki.nix ./prometheus.nix + ./uptime-kuma.nix ]; } diff --git a/modules/monitoring/uptime-kuma.nix b/modules/monitoring/uptime-kuma.nix new file mode 100644 index 0000000..bbb3bdf --- /dev/null +++ b/modules/monitoring/uptime-kuma.nix @@ -0,0 +1,60 @@ +{ + lib, + config, + pkgs, + ... +}: +let + cfg = config.my.monitoring.uptime-kuma; + port = 3001; +in +{ + + options.my.monitoring.uptime-kuma = { + enable = lib.mkEnableOption "Enable Uptime Kuma module"; + + proxy = { + enable = lib.mkEnableOption "Set the proxy entry for this service"; + + domain = lib.mkOption { + default = "example.com"; + type = lib.types.str; + description = '' + The domain where Caddy is reachable + ''; + }; + + host = lib.mkOption { + default = "localhost"; + type = lib.types.str; + description = '' + host name where the service is running + ''; + }; + + }; + }; + + config = lib.mkMerge [ + (lib.mkIf cfg.enable { + + services.uptime-kuma = { + enable = true; + settings = { + HOST = "::"; + PORT = toString port; + }; + }; + + }) + + (lib.mkIf cfg.proxy.enable { + services.caddy = with cfg.proxy; { + virtualHosts."up.${domain}".extraConfig = '' + reverse_proxy http://${host}:${port} + import cloudflare + ''; + }; + }) + ]; +}