diff --git a/hosts/caddy/default.nix b/hosts/caddy/default.nix index 2adee51..67d93d0 100644 --- a/hosts/caddy/default.nix +++ b/hosts/caddy/default.nix @@ -133,6 +133,15 @@ in cloudflareApiEnvName = "CLOUDFLARE_API_TOKEN"; } ]; + + extraVirtualHosts = [ + { + subdomain = "h"; + host = "http://ha.internal:8123"; + domain = publicDomain; + } + ]; + }; ddclient = { diff --git a/modules/networking/caddy.nix b/modules/networking/caddy.nix index ca87c55..37a8ad6 100644 --- a/modules/networking/caddy.nix +++ b/modules/networking/caddy.nix @@ -50,6 +50,32 @@ in default = ""; }; + # List of extra caddy.virtualHost + extraVirtualHosts = lib.mkOption { + type = lib.types.listOf ( + lib.types.submodule { + options = { + subdomain = lib.mkOption { + type = lib.types.str; + description = "The subdomain for the virtual host."; + }; + host = lib.mkOption { + type = lib.types.str; + description = "The host address for the reverse proxy."; + }; + domain = lib.mkOption { + type = lib.types.str; + description = "The domain for the virtual host."; + }; + }; + } + ); + description = '' + A list of virtual hosts outside nixos/colmena config. + ''; + default = [ ]; + }; + }; config = lib.mkIf cfg.enable { @@ -134,6 +160,17 @@ in ) cfg.domainsList ); + virtualHosts = lib.foldl' ( + acc: extraVirtualHost: + acc + // { + "${extraVirtualHost.subdomain}.${extraVirtualHost.domain}".extraConfig = '' + reverse_proxy ${extraVirtualHost.host} + import cloudflare_${extraVirtualHost.domain} + ''; + } + ) { } cfg.extraVirtualHosts; + }; systemd.services.caddy.serviceConfig = {