From caa476b35760f095d3ed4faa910939a136d73356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Wed, 21 Dec 2016 00:06:42 +0100 Subject: [PATCH] nixos/prometheus: add services.prometheus.configText option The structured options are incomplete compared to upstream and I think it will be a maintenance burden to try to keep up. Instead, provide an option for the raw config file contents (prometheus.yml). --- .../monitoring/prometheus/default.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/monitoring/prometheus/default.nix b/nixos/modules/services/monitoring/prometheus/default.nix index 82b97bd92f8..d692dd5fc79 100644 --- a/nixos/modules/services/monitoring/prometheus/default.nix +++ b/nixos/modules/services/monitoring/prometheus/default.nix @@ -25,9 +25,16 @@ let scrape_configs = cfg.scrapeConfigs; }; + generatedPrometheusYml = writePrettyJSON "prometheus.yml" promConfig; + + prometheusYml = + if cfg.configText != null then + pkgs.writeText "prometheus.yml" cfg.configText + else generatedPrometheusYml; + cmdlineArgs = cfg.extraFlags ++ [ "-storage.local.path=${cfg.dataDir}/metrics" - "-config.file=${writePrettyJSON "prometheus.yml" promConfig}" + "-config.file=${prometheusYml}" "-web.listen-address=${cfg.listenAddress}" "-alertmanager.notification-queue-capacity=${toString cfg.alertmanagerNotificationQueueCapacity}" "-alertmanager.timeout=${toString cfg.alertmanagerTimeout}s" @@ -359,6 +366,16 @@ in { ''; }; + configText = mkOption { + type = types.nullOr types.lines; + default = null; + description = '' + If non-null, this option defines the text that is written to + prometheus.yml. If null, the contents of prometheus.yml is generated + from the structured config options. + ''; + }; + globalConfig = mkOption { type = promTypes.globalConfig; default = {};