From 1c80dbef8b69edcdf20a18a0f21434d17416cef5 Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Tue, 10 Mar 2026 15:28:35 +0100 Subject: [PATCH] glance: Group sites more sensibly --- modules/nixos/meta/services.nix | 8 +++- modules/nixos/web-services/glance.nix | 64 ++++++++++++++++++++------- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/modules/nixos/meta/services.nix b/modules/nixos/meta/services.nix index fee970a..d8d6b8a 100644 --- a/modules/nixos/meta/services.nix +++ b/modules/nixos/meta/services.nix @@ -3,16 +3,20 @@ options.custom.meta.services = lib.mkOption { type = lib.types.attrsOf ( lib.types.submodule ( - { name, ... }: + { name, config, ... }: { options = { title = lib.mkOption { type = lib.types.nonEmptyStr; default = name; }; + domain = lib.mkOption { + type = lib.types.nonEmptyStr; + default = name; + }; url = lib.mkOption { type = lib.types.nonEmptyStr; - default = "https://${name}"; + default = "https://${config.domain}"; }; icon = lib.mkOption { type = lib.types.nonEmptyStr; diff --git a/modules/nixos/web-services/glance.nix b/modules/nixos/web-services/glance.nix index 498e91c..c5dbd18 100644 --- a/modules/nixos/web-services/glance.nix +++ b/modules/nixos/web-services/glance.nix @@ -1,5 +1,6 @@ { config, + self, lib, allHosts, ... @@ -7,23 +8,55 @@ let cfg = config.custom.web-services.glance; - servicesWidgets = - allHosts - |> lib.attrValues - |> lib.map (host: { - hostName = host.config.networking.hostName; - services = host.config.custom.meta.services |> lib.attrValues; - }) - |> lib.filter ({ services, ... }: services != [ ]) - |> lib.map ( - { hostName, services }: - { + observabilityTitles = [ + "Alloy" + "Prometheus" + "Alertmanager" + ]; + + hosts = allHosts |> lib.attrValues; + + applicationSites = + hosts + |> lib.concatMap (host: host.config.custom.meta.services |> lib.attrValues) + |> lib.filter (service: !lib.elem service.title observabilityTitles) + |> lib.groupBy ( + service: + service.domain |> self.lib.isPrivateDomain |> (isPrivate: if isPrivate then "Private" else "Public") + ) + |> lib.mapAttrsToList ( + name: value: { type = "monitor"; cache = "1m"; - title = "Services - ${hostName}"; - sites = services; + title = "${name} Services"; + sites = value; } - ); + ) + |> (widgets: { + type = "split-column"; + max-columns = 2; + inherit widgets; + }) + |> lib.singleton; + + observabilitySites = + hosts + |> lib.map (host: { + type = "monitor"; + cache = "1m"; + title = host.config.networking.hostName; + sites = + host.config.custom.meta.services + |> lib.attrValues + |> lib.filter (service: lib.elem service.title observabilityTitles); + }) + |> lib.filter ({ sites, ... }: sites != [ ]) + |> (widgets: { + type = "split-column"; + max-columns = widgets |> lib.length; + inherit widgets; + }) + |> lib.singleton; in { options.custom.web-services.glance = { @@ -57,7 +90,8 @@ in search-engine = "google"; autofocus = true; } - ++ servicesWidgets; + ++ applicationSites + ++ observabilitySites; }; }; };