all repos — nixfiles @ 88acd80ae0996f08300d3d3eef108b504106c118

System and user configuration, managed by nix and home-manager

router: add redirects for locally-hosted single-label domains

Alin
commit

88acd80ae0996f08300d3d3eef108b504106c118

parent

5eaf32e299a5b2222fa5c57e2252f70a62058cb2

1 file changed, 25 insertions(+), 0 deletions(-)

changed files
M system/roles/router.nix → system/roles/router.nix
@@ -50,6 +50,17 @@ lanCfg = config.networking.interfaces.${lan};
myAddresses = lib.filter (a: !(lib.strings.hasPrefix "fe80:" a)) ( map (lib.getAttr "address") (lanCfg.ipv4.addresses ++ lanCfg.ipv6.addresses) ); + + cnamesByTarget = lib.mapAttrs ( + _: + lib.concatMap ( + v: + lib.pipe v [ + (lib.dropEnd 1) + (map (lib.removeSuffix ".${domain}")) + ] + ) + ) (lib.groupBy lib.last (map (lib.splitString ",") config.services.dnsmasq.settings.cname)); in { imports = [
@@ -381,5 +392,19 @@ };
systemd.settings.Manager = { DefaultStartLimitIntervalSec = 0; + }; + + services.caddy.virtualHosts = { + "http://${hostName}" = { + serverAliases = map (n: "http://${n}") cnamesByTarget.${fqdn}; + extraConfig = '' + tls { + issuer internal { + ca home + } + } + redir https://{host}.${domain} + ''; + }; }; }