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;