refactor: abstract traefik router labels and dynamic config

This commit is contained in:
Tibo De Peuter 2026-07-17 23:29:17 +02:00
parent d742671460
commit 95e67dd151
Signed by: tdpeuter
SSH key fingerprint: SHA256:u/h/LVoqKF1Iz02uOyxe6hcjmoZASCGV2HM0TG9ZMoU
9 changed files with 152 additions and 74 deletions

View file

@ -12,6 +12,11 @@ in {
default = "traefik";
description = "The name of the shared network to connect the container to.";
};
dynamicConfigOptions = lib.mkOption {
type = lib.types.attrs;
default = {};
description = "Dynamic configuration options to write to file and mount into Traefik.";
};
};
config = lib.mkIf cfg.enable {
@ -35,6 +40,7 @@ in {
];
extraOptions = [
"--network=${cfg.sharedNetworkName}"
"--add-host=host.docker.internal:host-gateway"
];
environmentFiles = [
/home/admin/.cloudflare.secret
@ -46,6 +52,10 @@ in {
"--providers.docker=true"
"--providers.docker.exposedByDefault=false"
# Add File provider
"--providers.file.filename=/etc/traefik/dynamic_conf.yml"
"--providers.file.watch=true"
# Add web entrypoint
"--entrypoints.web.address=:80/tcp"
"--entrypoints.web.http.redirections.entrypoint.to=websecure"
@ -65,10 +75,14 @@ in {
"--certificatesresolvers.letsencrypt.acme.email=tibo.depeuter@telenet.be"
"--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
];
volumes = [
volumes = let
dynamicConfFormat = pkgs.formats.yaml { };
dynamicConfFile = dynamicConfFormat.generate "traefik-dynamic-conf.yml" cfg.dynamicConfigOptions;
in [
"letsencryp:/letsencrypt"
"/var/run/docker.sock:/var/run/docker.sock:ro"
"${dynamicConfFile}:/etc/traefik/dynamic_conf.yml:ro"
];
labels = {
"traefik.enable" = "true";