{ config, lib, ... }: let cfg = config.profile.services.caddy; inherit (lib) mkIf attrsets strings lists; in { config = mkIf cfg.enable { services.caddy = { enable = true; }; services.caddy.globalConfig = /*caddy*/ '' servers { metrics } ''; services.caddy.virtualHosts = let domains = attrsets.mapAttrsToList (name: _: strings.removePrefix "https://" name) config.services.caddy.virtualHosts; sortedDomains = lists.sort (a: b: a < b) domains; list = map (domain: /*html*/ ''
'') sortedDomains; items = strings.concatStringsSep "\n" list; html = /*html*/ ''