From cb9db0ed73ca65153af5d48f564bef22e8086717 Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Tue, 17 Nov 2026 13:16:57 +0400 Subject: [PATCH] traefik: routes from a watched file, no restart on a route change The NixOS module writes the routes (dynamicConfigOptions) into the static configuration, so every route change restarted Traefik: about 15 seconds with every site down (08:24 and 09:14 today; the second broke czsk's image push). The routes now go to /etc/traefik/dynamic.toml, a copy activation replaces, and Traefik's file provider watches it; the static configuration stays the same. This deploy restarts Traefik once. Assisted-by: Claude:opus-5-5 --- nixos/hosts/asxpio-ops/traefik.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nixos/hosts/asxpio-ops/traefik.nix b/nixos/hosts/asxpio-ops/traefik.nix index d7e5f10..da59ea5 100644 --- a/nixos/hosts/asxpio-ops/traefik.nix +++ b/nixos/hosts/asxpio-ops/traefik.nix @@ -54,10 +54,23 @@ in } ''; + # The routes go to a file Traefik watches, not into its static + # configuration: the NixOS module would otherwise write them into the + # static file, and every route change would restart Traefik (about 15 + # seconds with every site down). mode makes /etc hold a copy, which + # activation replaces, so the watch sees the change. + environment.etc."traefik/dynamic.toml" = { + source = + (pkgs.formats.toml { }).generate "dynamic.toml" + config.services.traefik.dynamicConfigOptions; + mode = "0444"; + }; + services.traefik = { enable = true; package = pkgs.traefik; environmentFiles = [ config.sops.templates."traefik.env".path ]; + dynamicConfigFile = "/etc/traefik/dynamic.toml"; staticConfigOptions = { api = { @@ -81,6 +94,7 @@ in addRoutersLabels = true; addServicesLabels = true; }; + providers.file.watch = true; # filename: dynamicConfigFile providers.docker = { endpoint = "unix:///run/podman/podman.sock"; exposedByDefault = false;