nix-configs

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

caddy-ilias.nix (1257B)


      1 { config, lib, pkgs, vars, ... }:
      2 
      3 # OpenWRT setup for custom *.home. domain names:
      4 # uci add_list dhcp.@dnsmasq[0].rebind_domain='home.minskio.co.uk'
      5 # uci add_list dhcp.@dnsmasq[0].address='/home.minskio.co.uk/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 = "${name}.home.${vars.user.domain}";
     19     value = {
     20       extraConfig = ''
     21         tls {
     22           dns cloudflare ${vars.secrets.cloudflare}
     23         }
     24         reverse_proxy ${svc.host}:${toString svc.port}
     25       '';
     26     };
     27   };
     28 in
     29 {
     30   services.caddy = {
     31     enable = true;
     32     package = pkgs.caddy.withPlugins {
     33       plugins = [ "github.com/caddy-dns/cloudflare@v0.2.4" ];
     34       hash = "sha256-7GoH8YLCoPmPExQxoga2FHB58zQDoZVf1BBwkVi0SsQ=";
     35     };
     36     virtualHosts = (lib.mapAttrs' mkVirtualHost services) // {
     37       # Handle http://192.168.1.3:80/ fallback to Stromboli
     38       "http://192.168.1.3" = { extraConfig = "reverse_proxy 127.0.0.1:8080"; };
     39     };
     40   };
     41 
     42   networking.firewall.allowedTCPPorts = [ 80 443 ];
     43 }