nixos-servers/kubenix-modules/custom/tailscale.nix

51 lines
1 KiB
Nix
Raw Normal View History

2024-07-21 17:47:22 +00:00
{ lib, config, ... }: {
options = with lib.types; {
2024-07-21 17:47:22 +00:00
lab.tailscaleIngresses = lib.mkOption {
type = attrsOf (submodule {
options = {
host = lib.mkOption { type = str; };
2024-07-21 17:47:22 +00:00
service = {
name = lib.mkOption { type = str; };
2024-07-21 17:47:22 +00:00
portName = lib.mkOption {
type = str;
default = "web";
};
};
};
});
};
};
config =
let
2024-07-21 17:47:22 +00:00
cfg = config.lab.tailscaleIngresses;
mkTailscaleIngress = name: { host, service }: {
spec = {
ingressClassName = "tailscale";
rules = [{
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = service.name;
port.name = service.portName;
};
}];
}];
2024-07-21 17:47:22 +00:00
tls = [{
hosts = [ host ];
}];
};
};
in
{
2024-07-21 17:47:22 +00:00
kubernetes.resources.ingresses = builtins.mapAttrs mkTailscaleIngress cfg;
};
}