2024-07-21 17:47:22 +00:00
|
|
|
{ lib, config, ... }: {
|
2024-07-21 14:26:21 +00:00
|
|
|
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 14:26:21 +00:00
|
|
|
|
2024-07-21 17:47:22 +00:00
|
|
|
service = {
|
|
|
|
name = lib.mkOption { type = str; };
|
2024-07-21 14:26:21 +00:00
|
|
|
|
2024-07-21 17:47:22 +00:00
|
|
|
portName = lib.mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "web";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
2024-07-21 14:26:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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 14:26:21 +00:00
|
|
|
}];
|
|
|
|
|
2024-07-21 17:47:22 +00:00
|
|
|
tls = [{
|
|
|
|
hosts = [ host ];
|
|
|
|
}];
|
2024-07-21 14:26:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2024-07-21 17:47:22 +00:00
|
|
|
kubernetes.resources.ingresses = builtins.mapAttrs mkTailscaleIngress cfg;
|
2024-07-21 14:26:21 +00:00
|
|
|
};
|
|
|
|
}
|