From 7df5b81fc3bfaa7b8102c7523f271be85239184a Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 28 Jul 2022 13:42:16 +0700 Subject: [PATCH] nixos/grafana-agent: ensure defaults are merged Move the defaults to the `config` section of the module, and apply them with mkDefault. That way the defaults are merged with user-provided config, and are merged without having to use lib.mkForce. --- .../services/monitoring/grafana-agent.nix | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/monitoring/grafana-agent.nix b/nixos/modules/services/monitoring/grafana-agent.nix index bbeda1846470..a4b18b4f28e9 100644 --- a/nixos/modules/services/monitoring/grafana-agent.nix +++ b/nixos/modules/services/monitoring/grafana-agent.nix @@ -48,9 +48,10 @@ in freeformType = settingsFormat.type; }; - default = { + default = { }; + defaultText = '' metrics = { - wal_directory = "\${STATE_DIRECTORY}"; + wal_directory = "\''${STATE_DIRECTORY}"; global.scrape_interval = "5s"; }; integrations = { @@ -59,8 +60,7 @@ in node_exporter.enabled = true; replace_instance_label = true; }; - }; - + ''; example = { metrics.global.remote_write = [{ url = "\${METRICS_REMOTE_WRITE_URL}"; @@ -104,6 +104,20 @@ in }; config = mkIf cfg.enable { + services.grafana-agent.settings = { + # keep this in sync with config.services.grafana-agent.settings.defaultText. + metrics = { + wal_directory = mkDefault "\${STATE_DIRECTORY}"; + global.scrape_interval = mkDefault "5s"; + }; + integrations = { + agent.enabled = mkDefault true; + agent.scrape_integration = mkDefault true; + node_exporter.enabled = mkDefault true; + replace_instance_label = mkDefault true; + }; + }; + systemd.services.grafana-agent = { wantedBy = [ "multi-user.target" ]; script = ''