about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorJonathan Davies <jpds@protonmail.com>2024-05-15 18:03:48 +0100
committerJonathan Davies <jpds@protonmail.com>2024-05-15 18:12:10 +0100
commit8d7f3c9dbde7d235f3e256f2dc13ec07e68f60f6 (patch)
treec7021c31bb2cf77da81b272df57908782891d492 /nixos
parent304f2767fab5ab26c0e7b3d17106d9a2cda73c65 (diff)
nixos/loki: Implement configuration verification
Fixes: #293088
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/monitoring/loki.nix9
1 files changed, 8 insertions, 1 deletions
diff --git a/nixos/modules/services/monitoring/loki.nix b/nixos/modules/services/monitoring/loki.nix
index ba63f95e7f1a8..a53830fd64c80 100644
--- a/nixos/modules/services/monitoring/loki.nix
+++ b/nixos/modules/services/monitoring/loki.nix
@@ -99,9 +99,16 @@ in {
         conf = if cfg.configFile == null
                then prettyJSON cfg.configuration
                else cfg.configFile;
+        validateConfig = file:
+        pkgs.runCommand "validate-loki-conf" {
+          nativeBuildInputs = [ pkgs.grafana-loki ];
+        } ''
+            loki -verify-config -config.file "${file}"
+            ln -s "${file}" "$out"
+          '';
       in
       {
-        ExecStart = "${cfg.package}/bin/loki --config.file=${conf} ${escapeShellArgs cfg.extraFlags}";
+        ExecStart = "${cfg.package}/bin/loki --config.file=${validateConfig conf} ${escapeShellArgs cfg.extraFlags}";
         User = cfg.user;
         Restart = "always";
         PrivateTmp = true;