From 47b35b5ed65f3498dc37b412ae6e1d1e2f679fd3 Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Sun, 29 Jun 2025 20:40:53 +0200 Subject: [PATCH] gatus: split ambiguous "endpoints" option into "customEndpoints" and internal "finalEndpoints" --- hosts/cumulus/default.nix | 11 +++++--- modules/system/services/gatus.nix | 44 ++++++++++++++++++------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/hosts/cumulus/default.nix b/hosts/cumulus/default.nix index 883e0e8..4b029e1 100644 --- a/hosts/cumulus/default.nix +++ b/hosts/cumulus/default.nix @@ -19,17 +19,20 @@ enable = true; domain = "status.${config.custom.services.tailscale.domain}"; endpointDomains = config.meta.domains.globalList; - endpoints = { - "status".group = "Monitoring"; + customEndpoints = { + "status" = { + group = "Monitoring"; + url = "https://${config.custom.services.gatus.domain}"; + }; "alerts" = { group = "Monitoring"; - appendPath = "/v1/health"; + url = "https://alerts.${config.custom.services.tailscale.domain}/v1/health"; extraConditions = [ "[BODY].healthy == true" ]; }; "git ssh".url = "ssh://git.sstork.dev"; }; }; - + ntfy = { enable = true; domain = "alerts.${config.custom.services.tailscale.domain}"; diff --git a/modules/system/services/gatus.nix b/modules/system/services/gatus.nix index 4dd336b..d70c2be 100644 --- a/modules/system/services/gatus.nix +++ b/modules/system/services/gatus.nix @@ -1,6 +1,20 @@ { config, lib, ... }: let cfg = config.custom.services.gatus; + + defaultEndpoints = + let + getSubdomain = domain: domain |> lib.splitString "." |> lib.head; + in + cfg.endpointDomains + |> lib.map ( + domain: + lib.nameValuePair (getSubdomain domain) { + name = getSubdomain domain; + url = "https://${domain}"; + } + ) + |> lib.listToAttrs; in { options.custom.services.gatus = { @@ -17,7 +31,7 @@ in type = lib.types.listOf lib.types.nonEmptyStr; default = [ ]; }; - endpoints = lib.mkOption { + customEndpoints = lib.mkOption { type = lib.types.attrsOf ( lib.types.submodule ( { name, ... }: @@ -35,10 +49,6 @@ in type = lib.types.nonEmptyStr; default = ""; }; - appendPath = lib.mkOption { - type = lib.types.str; - default = ""; - }; extraConditions = lib.mkOption { type = lib.types.listOf lib.types.nonEmptyStr; default = [ ]; @@ -49,6 +59,11 @@ in ); default = { }; }; + finalEndpoints = lib.mkOption { + type = lib.types.attrsOf lib.types.anything; + default = defaultEndpoints // cfg.customEndpoints; + readOnly = true; + }; }; config = lib.mkIf cfg.enable { @@ -61,14 +76,6 @@ in ''; }; - custom.services.gatus.endpoints = - let - getSubdomain = domain: domain |> lib.splitString "." |> lib.head; - in - cfg.endpointDomains - |> lib.map (domain: lib.nameValuePair (getSubdomain domain) { url = "https://${domain}"; }) - |> lib.listToAttrs; - services.gatus = { enable = true; environmentFile = config.sops.templates."gatus.env".path; @@ -108,10 +115,9 @@ in mkEndpoint = ( { name, - group, + group ? null, url, - appendPath, - extraConditions, + extraConditions ? [ ], }: let isPrivate = lib.hasInfix config.custom.services.tailscale.domain url; @@ -120,7 +126,7 @@ in { inherit name; group = if group != null then group else deducedGroup; - url = url + appendPath; + url = url; alerts = [ { type = "ntfy"; } ]; ssh = lib.mkIf (lib.hasPrefix "ssh" url) { username = ""; @@ -144,7 +150,9 @@ in conditions = [ "[STATUS] == 200" ]; } ] - ++ (cfg.endpoints |> lib.mapAttrsToList (_: value: value) |> lib.map (entry: mkEndpoint entry)); + ++ ( + cfg.finalEndpoints |> lib.mapAttrsToList (_: value: value) |> lib.map (entry: mkEndpoint entry) + ); }; }; };