1
Fork 0
satellite/modules/nixos/cloudflared.nix

38 lines
1 KiB
Nix
Raw Normal View History

2024-05-09 15:20:03 +02:00
{ config, lib, ... }:
let cfg = config.satellite.cloudflared;
in
{
options.satellite.cloudflared = {
tunnel = lib.mkOption {
type = lib.types.str;
2024-05-11 01:09:43 +02:00
description = "Cloudflare tunnel id to use for the `satellite.cloudflared.targets` helper";
2024-05-09 15:20:03 +02:00
};
2024-05-11 01:09:43 +02:00
targets = lib.mkOption {
description = "List of hosts to set up ingress rules for";
default = { };
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: {
options = {
port = lib.mkOption {
type = lib.types.port;
description = "Localhost port to point the tunnel at";
};
2024-05-09 15:20:03 +02:00
2024-05-11 01:09:43 +02:00
host = lib.mkOption {
default = name;
type = lib.types.str;
2024-05-11 01:09:43 +02:00
description = "Host to direct traffic from";
};
};
}));
2024-05-09 15:20:03 +02:00
};
};
2024-05-11 01:09:43 +02:00
config.services.cloudflared.tunnels.${cfg.tunnel}.ingress = lib.attrsets.mapAttrs'
(_: { port, host }: {
name = host;
value = "http://localhost:${toString port}";
})
cfg.targets;
2024-05-09 15:20:03 +02:00
}