{
  config,
  lib,
  ...
}: {
  services.n8n = {
    enable = true;
    environment.WEBHOOK_URL = "https://wf.m3tam3re.com";
  };
  # Temporary fix for upstream module
  systemd.services.n8n.serviceConfig.LoadCredential = lib.mkForce [];
  systemd.services.n8n.environment.N8N_RUNNERS_AUTH_TOKEN_FILE = lib.mkForce null;

  systemd.services.n8n.serviceConfig = {
    EnvironmentFile = ["${config.age.secrets.n8n-env.path}"];
  };
  # Traefik configuration specific to n8n
  services.traefik.dynamicConfigOptions.http = {
    services.n8n.loadBalancer.servers = [
      {
        url = "http://localhost:5678/";
      }
    ];

    routers.n8n = {
      rule = "Host(`wf.m3ta.dev`)";
      tls = {
        certResolver = "godaddy";
      };
      service = "n8n";
      entrypoints = "websecure";
    };
  };
}
