{ config, self, lib, allHosts, ... }: let cfg = config.custom.web-services.glance; perHostDomains = perHostSitesWidget.widgets |> lib.concatMap (widget: widget.sites) |> lib.map (site: site.domain); perHostSitesWidget = allHosts |> lib.attrValues |> lib.map (host: { type = "monitor"; cache = "1m"; title = host.config.networking.hostName; sites = host.config.custom.meta.sites |> lib.attrValues |> lib.filter (site: site.domain |> lib.hasSuffix host.config.custom.networking.overlay.fqdn); }) |> lib.filter ({ sites, ... }: sites != [ ]) |> (widgets: { type = "split-column"; max-columns = widgets |> lib.length; inherit widgets; }); applicationSitesWidget = allHosts |> lib.attrValues |> lib.concatMap (host: host.config.custom.meta.sites |> lib.attrValues) |> lib.filter (service: !lib.elem service.domain perHostDomains) |> lib.groupBy ( service: service.domain |> self.lib.isPrivateDomain |> (isPrivate: if isPrivate then "Private" else "Public") ) |> lib.mapAttrsToList ( name: value: { type = "monitor"; cache = "1m"; title = "${name} Services"; sites = value; } ) |> (widgets: { type = "split-column"; max-columns = 2; inherit widgets; }); githubWorkflowFiles = "${self}/.github/workflows" |> builtins.readDir |> lib.attrNames |> lib.filter (file: file |> lib.hasSuffix ".yml") |> lib.filter (file: file |> lib.hasPrefix "_" |> (hasPrefix: !hasPrefix)); mkGithubWorkflowBadge = workflowFile: let workflowName = workflowFile |> lib.removeSuffix ".yml"; workflowUrl = "https://github.com/SebastianStork/nixos-config/actions/workflows/${workflowFile}"; in '' ${workflowName} workflow status ''; githubWorkflowBadges = githubWorkflowFiles |> lib.map mkGithubWorkflowBadge |> lib.concatStringsSep "\n"; githubBadgeWidget = { type = "custom-api"; title = "nixos-config"; title-url = "https://github.com/SebastianStork/nixos-config"; template = ''
${githubWorkflowBadges}
''; }; in { options.custom.web-services.glance = { enable = lib.mkEnableOption ""; domain = lib.mkOption { type = lib.types.nonEmptyStr; default = ""; }; port = lib.mkOption { type = lib.types.port; default = 63958; }; }; config = lib.mkIf cfg.enable { services.glance = { enable = true; settings = { server.port = cfg.port; pages = lib.singleton { name = "Home"; center-vertically = true; columns = [ { size = "full"; widgets = [ { type = "search"; search-engine = "https://search.splitleaf.de/search?q={QUERY}"; autofocus = false; } applicationSitesWidget perHostSitesWidget ]; } { size = "small"; widgets = [ githubBadgeWidget ]; } ]; }; }; }; custom.services.caddy.virtualHosts.${cfg.domain}.port = cfg.port; }; }