From ed60032f755e0aef26b3a79f43fbfc8b218523cf Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Sun, 13 Oct 2024 16:01:52 +0700 Subject: [PATCH] caddy: fix indentation for static site Fix by moving the inline HTML to a separate file and serve it using `file_server` directive. --- system/services/caddy.nix | 81 +++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/system/services/caddy.nix b/system/services/caddy.nix index 51fa728..1f6a910 100644 --- a/system/services/caddy.nix +++ b/system/services/caddy.nix @@ -1,4 +1,4 @@ -{ config, lib, ... }: +{ config, lib, unstable, ... }: let cfg = config.profile.services.caddy; inherit (lib) mkIf attrsets strings lists; @@ -7,6 +7,7 @@ in config = mkIf cfg.enable { services.caddy = { enable = true; + package = unstable.caddy; }; services.caddy.globalConfig = /*caddy*/ '' @@ -15,36 +16,44 @@ in } ''; + environment.etc."caddy/static/tigor.web.id/index.html" = { + text = + 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*/ '' +
+ ${domain} +
+ '') + sortedDomains; + items = strings.concatStringsSep "\n" list; + in + /*html*/ '' + + + + Hosted Sites + + + +

Hosted Sites

+
+ ${items} +
+ + + ''; + user = "caddy"; + group = "caddy"; + }; + 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*/ '' -
- ${domain} -
'') - sortedDomains; - items = strings.concatStringsSep "\n" list; - html = /*html*/ - '' - - - Hosted Sites - - - -

Hosted Sites

-
- ${items} -
- - ''; - in { "router.tigor.web.id".extraConfig = '' @denied not remote_ip private_ranges @@ -55,17 +64,13 @@ in ''; "tigor.web.id".extraConfig = '' - header Content-Type text/html - respond <