about summary refs log tree commit diff
path: root/modules/nixos/monitoring/default.nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/nixos/monitoring/default.nix36
1 files changed, 24 insertions, 12 deletions
diff --git a/modules/nixos/monitoring/default.nix b/modules/nixos/monitoring/default.nix
index fbc0e60..5aed215 100644
--- a/modules/nixos/monitoring/default.nix
+++ b/modules/nixos/monitoring/default.nix
@@ -32,27 +32,27 @@ in {
 
           # https://grafana.com/docs/grafana/latest/administration/provisioning/#data-sources
           datasources.settings.datasources = with config.nixfiles.modules; [
-            {
+            (mkIf alertmanager.enable {
               name = "Alertmanager";
               type = "alertmanager";
               access = "proxy";
-              jsonData.implementation = "prometheus";
               url = "https://${alertmanager.domain}";
-            }
-            {
+              jsonData.implementation = "prometheus";
+            })
+            (mkIf loki.enable {
               name = "Loki";
               type = "loki";
               access = "proxy";
               url = "https://${loki.domain}";
               isDefault = true;
-            }
-            {
+            })
+            (mkIf prometheus.enable {
               name = "Prometheus";
               type = "prometheus";
               access = "proxy";
               url = "https://${prometheus.domain}";
-            }
-            (mkIf config.nixfiles.modules.redis.enable {
+            })
+            (mkIf redis.enable {
               name = "Redis";
               type = "redis-datasource";
               access = "proxy";
@@ -60,11 +60,23 @@ in {
               jsonData.client = "standalone";
             })
           ];
-          datasources.settings.deleteDatasources = [
-            {
-              name = "PostgreSQL";
+          datasources.settings.deleteDatasources = with config.nixfiles.modules; [
+            (mkIf (!alertmanager.enable) {
+              name = "Alertmanager";
               orgId = 1;
-            }
+            })
+            (mkIf (!loki.enable) {
+              name = "Loki";
+              orgId = 1;
+            })
+            (mkIf (!prometheus.enable) {
+              name = "Prometheus";
+              orgId = 1;
+            })
+            (mkIf (!redis.enable) {
+              name = "Redis";
+              orgId = 1;
+            })
           ];
 
           # https://grafana.com/docs/grafana/latest/administration/provisioning/#dashboards

Consider giving Nix/NixOS a try! <3