kubernetes-deployments/modules/tailscale-ingress.nix

64 lines
1.1 KiB
Nix
Raw Normal View History

2024-10-28 15:05:06 +00:00
{
lib,
config,
...
}: {
2024-09-07 10:35:02 +00:00
options = with lib.types; {
lab.tailscaleIngresses = lib.mkOption {
type = attrsOf (submodule {
options = {
2024-10-28 15:05:06 +00:00
host = lib.mkOption {type = str;};
2024-09-07 10:35:02 +00:00
service = {
2024-10-28 15:05:06 +00:00
name = lib.mkOption {type = str;};
2024-09-07 10:35:02 +00:00
portName = lib.mkOption {
type = str;
default = "web";
};
};
};
});
2024-10-28 15:05:06 +00:00
default = {};
2024-09-07 10:35:02 +00:00
};
};
2024-10-28 15:05:06 +00:00
config = let
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;
};
}
];
}
];
tls = [
{
hosts = [host];
}
];
2024-09-07 10:35:02 +00:00
};
};
2024-10-28 15:05:06 +00:00
in {
kubernetes.resources.ingresses = builtins.mapAttrs mkTailscaleIngress cfg;
};
2024-09-07 10:35:02 +00:00
}