From fea90592fe4c32b71d03a37e810d1ceaeb919fcd Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Mon, 1 Nov 2021 15:26:11 -0400 Subject: [PATCH] Add middlewares to traefik config --- modules/cloud/traefik/config.nix | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/cloud/traefik/config.nix b/modules/cloud/traefik/config.nix index 602cacc..1925a91 100644 --- a/modules/cloud/traefik/config.nix +++ b/modules/cloud/traefik/config.nix @@ -4,6 +4,22 @@ with lib; let 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 { options = { host = mkOption { @@ -29,6 +45,11 @@ let default = [ "https" ]; 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; tls.certResolver = "le"; service = "${name}-service"; + middlewares = lists.imap0 (id: m: "${name}-middleware-${toString id}") host.middlewares; }; http.services."${name}-service".loadBalancer.servers = [ { url = "http://localhost:${toString host.port}"; } ]; + http.middlewares = builtins.listToAttrs (lists.imap0 (id: v: { + name = "${name}-middleware-${toString id}"; + value = v; + }) host.middlewares); }; in {