2024-07-04 19:12:52 +03:00
|
|
|
{ config, lib, name, options, ... }:
|
2024-07-04 02:57:36 +03:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
internal = mkOption {
|
|
|
|
description = "Whether to only make this Way available internally. Will use the internal subdomain.";
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
2024-07-04 19:12:52 +03:00
|
|
|
description = "Domain name to use.";
|
2024-07-04 02:57:36 +03:00
|
|
|
type = types.str;
|
2024-07-04 19:12:52 +03:00
|
|
|
default = let
|
|
|
|
basename = "${name}.${config.domainSuffix}";
|
|
|
|
in if config.wildcard then "~^(.+)\.${lib.escapeRegex basename}$" else basename;
|
|
|
|
};
|
|
|
|
|
|
|
|
dnsRecord = {
|
|
|
|
name = mkOption {
|
|
|
|
description = "DNS record name for this Way.";
|
|
|
|
type = types.str;
|
|
|
|
default = if config.wildcard then "^[^_].+\\.${lib.escapeRegex name}" else name;
|
|
|
|
};
|
|
|
|
|
|
|
|
value = mkOption {
|
|
|
|
description = "DNS record value for this Way.";
|
|
|
|
type = types.deferredModule;
|
|
|
|
default = {
|
|
|
|
consulService = "${name}.ways-proxy";
|
|
|
|
rewrite.type = lib.mkIf config.wildcard "regex";
|
|
|
|
};
|
|
|
|
};
|
2024-07-04 02:57:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
target = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
2024-07-04 19:12:52 +03:00
|
|
|
wildcard = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
2024-07-04 18:03:39 +03:00
|
|
|
consulService = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
2024-07-04 02:57:36 +03:00
|
|
|
healthCheckPath = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/.well-known/ways/internal-health-check";
|
|
|
|
};
|
|
|
|
|
2024-07-04 18:03:39 +03:00
|
|
|
useConsul = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
internal = true;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
nginxUpstreamName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
|
2024-07-04 19:12:52 +03:00
|
|
|
domainSuffixInternal = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
domainSuffixExternal = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
domainSuffix = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
internal = true;
|
|
|
|
default = if config.internal then config.domainSuffixInternal else config.domainSuffixExternal;
|
|
|
|
};
|
|
|
|
|
2024-07-04 02:57:36 +03:00
|
|
|
extras = mkOption {
|
|
|
|
description = "Extra configuration to pass to the nginx virtual host submodule.";
|
|
|
|
type = types.deferredModule;
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
};
|
2024-07-04 18:03:39 +03:00
|
|
|
|
|
|
|
config = lib.mkMerge [
|
|
|
|
(lib.mkIf options.consulService.isDefined {
|
|
|
|
useConsul = true;
|
|
|
|
nginxUpstreamName = "ways_upstream_${builtins.hashString "md5" options.consulService.value}";
|
|
|
|
target = "http://${options.nginxUpstreamName.value}";
|
|
|
|
})
|
|
|
|
];
|
2024-07-04 02:57:36 +03:00
|
|
|
}
|