nix-configs

Personal NixOS and home-manager configuration files
Log | Files | Refs

caddy-ilias.nix (880B)


      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     music  = { host = "127.0.0.1"; port = 4533; };
     12     stream = { host = "127.0.0.1"; port = 8080; };
     13     weight = { host = "127.0.0.1"; port = 9090; };
     14   };
     15 
     16   mkVirtualHost = name: svc: {
     17     name = "http://${name}.lan";
     18     value = {
     19       extraConfig = ''
     20         reverse_proxy ${svc.host}:${toString svc.port}
     21       '';
     22     };
     23   };
     24 in
     25 {
     26   services.caddy = {
     27     enable = true;
     28     virtualHosts = (lib.mapAttrs' mkVirtualHost services) // {
     29       "http://192.168.1.3" = {
     30         extraConfig = ''
     31           reverse_proxy 127.0.0.1:8080
     32         '';
     33       };
     34     };
     35   };
     36 
     37   networking.firewall.allowedTCPPorts = [ 80 ];
     38 }