2024-05-09 15:20:03 +02:00
|
|
|
{ config, lib, ... }:
|
2024-09-11 16:30:19 +02:00
|
|
|
let
|
|
|
|
cfg = config.satellite.cloudflared;
|
2024-05-09 15:20:03 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.satellite.cloudflared = {
|
|
|
|
tunnel = lib.mkOption {
|
2024-05-21 01:56:53 +02:00
|
|
|
type = lib.types.str;
|
2024-07-06 19:32:14 +02:00
|
|
|
description = "Cloudflare tunnel id to use for the `satellite.cloudflared.at` helper";
|
2024-05-09 15:20:03 +02:00
|
|
|
};
|
|
|
|
|
2024-07-08 03:06:27 +02:00
|
|
|
domain = lib.mkOption {
|
|
|
|
description = "Root domain to use as a default for configurations.";
|
|
|
|
type = lib.types.str;
|
|
|
|
default = config.satellite.dns.domain;
|
|
|
|
};
|
|
|
|
|
2024-07-06 19:32:14 +02:00
|
|
|
at = lib.mkOption {
|
2024-05-11 01:09:43 +02:00
|
|
|
description = "List of hosts to set up ingress rules for";
|
|
|
|
default = { };
|
2024-09-11 16:30:19 +02:00
|
|
|
type = lib.types.attrsOf (
|
|
|
|
lib.types.submodule (
|
|
|
|
{ name, config, ... }:
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
subdomain = lib.mkOption {
|
|
|
|
description = ''
|
|
|
|
Subdomain to use for host generation.
|
|
|
|
Only required if `host` is not set manually.
|
|
|
|
'';
|
|
|
|
type = lib.types.str;
|
|
|
|
default = name;
|
|
|
|
};
|
2024-07-08 03:06:27 +02:00
|
|
|
|
2024-09-11 16:30:19 +02:00
|
|
|
port = lib.mkOption {
|
|
|
|
description = "Localhost port to point the tunnel at";
|
|
|
|
type = lib.types.port;
|
|
|
|
};
|
2024-05-09 15:20:03 +02:00
|
|
|
|
2024-09-11 16:30:19 +02:00
|
|
|
host = lib.mkOption {
|
|
|
|
description = "Host to direct traffic from";
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "${config.subdomain}.${cfg.domain}";
|
|
|
|
};
|
2024-07-08 03:06:27 +02:00
|
|
|
|
2024-09-11 16:30:19 +02:00
|
|
|
protocol = lib.mkOption {
|
|
|
|
description = "The protocol to redirect traffic through";
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "http";
|
|
|
|
};
|
|
|
|
|
|
|
|
url = lib.mkOption {
|
|
|
|
description = "External https url used to access this host";
|
|
|
|
type = lib.types.str;
|
|
|
|
};
|
|
|
|
};
|
2024-07-08 03:06:27 +02:00
|
|
|
|
2024-09-11 16:30:19 +02:00
|
|
|
config.url = "https://${config.host}";
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2024-05-09 15:20:03 +02:00
|
|
|
};
|
|
|
|
};
|
2024-05-11 01:09:43 +02:00
|
|
|
|
2024-09-11 16:30:19 +02:00
|
|
|
config.services.cloudflared.tunnels.${cfg.tunnel}.ingress = lib.attrsets.mapAttrs' (
|
|
|
|
_:
|
|
|
|
{
|
|
|
|
port,
|
|
|
|
host,
|
|
|
|
protocol,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
{
|
2024-05-11 01:09:43 +02:00
|
|
|
name = host;
|
2024-09-11 16:30:19 +02:00
|
|
|
value = "${protocol}://localhost:${toString port}";
|
|
|
|
}
|
|
|
|
) cfg.at;
|
2024-07-08 03:06:27 +02:00
|
|
|
|
|
|
|
config.satellite.dns.records =
|
2024-09-11 16:30:19 +02:00
|
|
|
let
|
|
|
|
mkDnsRecord =
|
|
|
|
{ subdomain, ... }:
|
|
|
|
{
|
|
|
|
type = "CNAME";
|
|
|
|
at = subdomain;
|
|
|
|
zone = cfg.domain;
|
|
|
|
value = "${cfg.tunnel}.cfargotunnel.com.";
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.attrsets.mapAttrsToList (_: mkDnsRecord) cfg.at;
|
2024-05-09 15:20:03 +02:00
|
|
|
}
|