caddy-ilias.nix (931B)
1 { config, lib, pkgs, ... }: 2 3 # OpenWRT setup for custom LAN domain names: 4 # uci add_list dhcp.@dnsmasq[0].rebind_domain='lan' 5 # uci add_list dhcp.@dnsmasq[0].address='/example.lan/192.168.1.3' 6 # uci commit dhcp 7 # service dnsmasq restart 8 9 let 10 services = { 11 drink = { host = "127.0.0.1"; port = 9092; }; 12 pub = { host = "127.0.0.1"; port = 9091; }; 13 stream = { host = "127.0.0.1"; port = 8080; }; 14 weight = { host = "127.0.0.1"; port = 9090; }; 15 }; 16 17 mkVirtualHost = name: svc: { 18 name = "http://${name}.lan"; 19 value = { 20 extraConfig = '' 21 reverse_proxy ${svc.host}:${toString svc.port} 22 ''; 23 }; 24 }; 25 in 26 { 27 services.caddy = { 28 enable = true; 29 virtualHosts = (lib.mapAttrs' mkVirtualHost services) // { 30 "http://192.168.1.3" = { 31 extraConfig = '' 32 reverse_proxy 127.0.0.1:8080 33 ''; 34 }; 35 }; 36 }; 37 38 networking.firewall.allowedTCPPorts = [ 80 ]; 39 }