{ data, lib, ... }: let pns = data.services; marvinIP = data.hosts.marvin.ts.ip4; marvin = "http://${marvinIP}"; inherit (data) tsNet; in rec { /** Caddy multiple host creation function Allows creation of a set of caddy hosts, based on a function and a list of service names # Example ```nix mkHosts mkDirect [ "service-a" "service-b" ] ``` # Type ``` mkHosts :: Function -> [String] -> AttrSet ``` # Arguments - [function] The function to be applied to the services list - [services] The services to pass to the function */ mkHosts = function: services: lib.listToAttrs (map function services); /** Anubis-proxied host creation function Allows creation of an Anubis-proxied host # Example ```nix mkAnubis "service-a" => { service-a = { extraConfig = '' reverse_proxy 100.123.15.72:1234 { header_up X-Real-Ip {remote_host} header_up X-Http-Version {http.request.proto} } ''; }; } ``` # Type ``` mkAnubis :: String -> AttrSet ``` # Arguments - [service] The service to create a caddy host for */ mkAnubis = service: lib.nameValuePair "${pns.${service}.extUrl}" { extraConfig = '' reverse_proxy ${marvin}:${toString pns.${service}.anubis} { header_up X-Real-Ip {remote_host} header_up X-Http-Version {http.request.proto} } ''; }; /** Anubis-proxied multiple host creation function Allows creation of several Anubis-proxied hosts # Example ```nix mkAnubisSites ["service-a"] => { service-a = { extraConfig = '' reverse_proxy 100.123.15.72:1234 { header_up X-Real-Ip {remote_host} header_up X-Http-Version {http.request.proto} } ''; }; } ``` # Type ``` mkAnubisSites :: [String] -> AttrSet ``` # Arguments - [services] The list of services to create Caddy hosts for */ mkAnubisSites = services: mkHosts mkAnubis services; /** Tailscale-only host creation function Allows creation of a service that will only be offered inside the tailnet. # Example ```nix mkTs "service-a" => { "service-a.example.ts.net" = { extraConfig = '' bind tailscale/service-a tailscale_auth reverse_proxy 100.123.15.72:1234 ''; }; } ``` # Type ``` mkTs :: String -> AttrSet ``` # Arguments - [service] The service to create a Tailscale-only host for */ mkTs = service: lib.nameValuePair "${pns.${service}.tsHost}.${tsNet}" { extraConfig = '' bind tailscale/${pns.${service}.tsHost} tailscale_auth reverse_proxy ${marvin}:${toString pns.${service}.port} ''; }; /** Tailscale-only multiple host creation function Allows creation of several Tailscale-only hosts # Example ```nix mkTs ["service-a"] => { "service-a.example.ts.net" = { extraConfig = '' bind tailscale/service-a tailscale_auth reverse_proxy 100.123.15.72:1234 ''; }; } ``` # Type ``` mkTsSites :: [String] -> AttrSet ``` # Arguments - [services] The list of services to create Tailscale-only hosts for */ mkTsSites = services: mkHosts mkTs services; /** Direct connection host creation function Allows creation of a service that will be proxied via Caddy, but not protected by Anubis. # Example ```nix mkDirect "service-a" => { "service-a.example.com" = { extraConfig = '' reverse_proxy 100.123.15.72:1234 ''; }; } ``` # Type ``` mkDirect :: String -> AttrSet ``` # Arguments - [service] The service to create a direct host for */ mkDirect = service: lib.nameValuePair "${pns.${service}.extUrl}" { extraConfig = '' reverse_proxy ${marvin}:${toString pns.${service}.port} ''; }; /** Direct connection multiple host creation function Allows creation of several directly-connected hosts # Example ```nix mkDirectSites ["service-a"] => { "service-a.example.com" = { extraConfig = '' reverse_proxy 100.123.15.72:1234 ''; }; } ``` # Type ``` mkDirectSites :: [String] -> AttrSet ``` # Arguments - [services] The list of services to create Tailscale-only hosts for */ mkDirectSites = services: mkHosts mkDirect services; }