Add middlewares to traefik config
This commit is contained in:
parent
798ae2004a
commit
fea90592fe
|
@ -4,6 +4,22 @@ with lib;
|
||||||
let
|
let
|
||||||
cfg = config.cloud.traefik;
|
cfg = config.cloud.traefik;
|
||||||
|
|
||||||
|
# Copied from traefik.nix
|
||||||
|
jsonValue = with types;
|
||||||
|
let
|
||||||
|
valueType = nullOr (oneOf [
|
||||||
|
bool
|
||||||
|
int
|
||||||
|
float
|
||||||
|
str
|
||||||
|
(lazyAttrsOf valueType)
|
||||||
|
(listOf valueType)
|
||||||
|
]) // {
|
||||||
|
description = "JSON value";
|
||||||
|
emptyValue.value = { };
|
||||||
|
};
|
||||||
|
in valueType;
|
||||||
|
|
||||||
hostType = with types; submodule {
|
hostType = with types; submodule {
|
||||||
options = {
|
options = {
|
||||||
host = mkOption {
|
host = mkOption {
|
||||||
|
@ -29,6 +45,11 @@ let
|
||||||
default = [ "https" ];
|
default = [ "https" ];
|
||||||
description = "The entrypoints that will serve the host";
|
description = "The entrypoints that will serve the host";
|
||||||
};
|
};
|
||||||
|
middlewares = mkOption {
|
||||||
|
type = listOf jsonType;
|
||||||
|
default = [];
|
||||||
|
description = "The middlewares to be used with the host.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,10 +66,15 @@ let
|
||||||
entryPoints = host.entrypoints;
|
entryPoints = host.entrypoints;
|
||||||
tls.certResolver = "le";
|
tls.certResolver = "le";
|
||||||
service = "${name}-service";
|
service = "${name}-service";
|
||||||
|
middlewares = lists.imap0 (id: m: "${name}-middleware-${toString id}") host.middlewares;
|
||||||
};
|
};
|
||||||
http.services."${name}-service".loadBalancer.servers = [
|
http.services."${name}-service".loadBalancer.servers = [
|
||||||
{ url = "http://localhost:${toString host.port}"; }
|
{ url = "http://localhost:${toString host.port}"; }
|
||||||
];
|
];
|
||||||
|
http.middlewares = builtins.listToAttrs (lists.imap0 (id: v: {
|
||||||
|
name = "${name}-middleware-${toString id}";
|
||||||
|
value = v;
|
||||||
|
}) host.middlewares);
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue