aboutsummaryrefslogtreecommitdiff
path: root/modules/services/nixos/mkCaddyCfg.nix
blob: d7b74c01ff1cf9b4267cb449deb17241b5aef3d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
cfg: {
  networking.extraHosts =
    if cfg.caddy.local.enable
    then ''
      127.0.0.1 ${cfg.service_name}.collinux
    ''
    else "";

  services.caddy.virtualHosts =
    (
      if cfg.caddy.global.enable && (cfg.root_url != null)
      then {
        ${cfg.root_url}.extraConfig = ''
          ${
            if cfg.caddy.bind_tailscale
            then "bind tailscale/${cfg.service_name}"
            else ""
          }
          reverse_proxy ${cfg.bind_host}:${toString cfg.port}
        '';
      }
      else {}
    )
    // (
      if cfg.caddy.local.enable
      then {
        "${cfg.service_name}.collinux".extraConfig = ''
          tls internal
          reverse_proxy ${cfg.bind_host}:${toString cfg.port}
        '';
      }
      else {}
    );
}