Files
dev/configs/nixos/registry/route.nix

70 lines
1.5 KiB
Nix

{ lib, util, ... }:
let
# NOLINT(let_order)
routeType =
protocols: options:
lib.types.submodule {
options = {
domain = lib.mkOption {
type = lib.types.str;
example = "files.alexion.dev";
description = "Public domain for this route.";
};
protocol = lib.mkOption {
type = lib.types.enum protocols;
description = "Public protocol for this route.";
};
}
// options;
};
webRoute =
routeType
[
"http"
"https"
]
{
port = lib.mkOption {
type = lib.types.port;
example = 3923;
description = "HTTP backend port for this route.";
};
};
udpRoute = routeType [ "udp" ] {
ports = lib.mkOption {
type = lib.types.nonEmptyListOf lib.types.port;
example = [
2456
2457
];
description = "UDP ports for this route.";
};
};
in
{
checks = [
{
assertion = util.registry.predicates.uniqueValue (entry: entry.value.domain);
message = "Route domains must be unique.";
}
{
assertion =
entries:
util.registry.predicates.uniqueValue (entry: entry.value) (
lib.concatMap (entry: map (port: entry // { value = port; }) entry.value.ports) (
lib.filter (entry: entry.value.protocol == "udp") entries
)
);
message = "Route UDP ports must be unique.";
}
];
type = lib.types.oneOf [
webRoute
udpRoute
];
}