Unverified Commit 100c1501 authored by emilylange's avatar emilylange
Browse files

nixos/loki: skip config validation when it's impossible to validate

This is a follow-up to 8d7f3c9d and
ae48735c.

Running the config validation in the build sandbox is impossible and
will fail when using `cfg.configFile` or `-config.expand-env=true`.

`cfg.configFile` is a string of a path which is simply not available to
the build sandbox.

Similarly, one may opt to use `cfg.configuration` with environment
variables in combination with `-config.expand-env=true`.

The environment variables referenced that way are also not available
in the build sandbox.

So we skip the validation when it's impossible (`cfg.configFile`) or
likely impossible (`-config.expand-env=true`).

An alternative approach would be something like nixos/prometheus'
`services.prometheus.checkConfig` that takes a boolean and makes
toggling the config validation user-facing.
parent 68ead292
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -97,7 +97,12 @@ in {

      serviceConfig = let
        conf = if cfg.configFile == null
               then prettyJSON cfg.configuration
               then
                 # Config validation may fail when using extraFlags = [ "-config.expand-env=true" ].
                 # To work around this, we simply skip it when extraFlags is not empty.
                 if cfg.extraFlags == []
                 then validateConfig (prettyJSON cfg.configuration)
                 else prettyJSON cfg.configuration
               else cfg.configFile;
        validateConfig = file:
        pkgs.runCommand "validate-loki-conf" {
@@ -108,7 +113,7 @@ in {
          '';
      in
      {
        ExecStart = "${cfg.package}/bin/loki --config.file=${validateConfig conf} ${escapeShellArgs cfg.extraFlags}";
        ExecStart = "${cfg.package}/bin/loki --config.file=${conf} ${escapeShellArgs cfg.extraFlags}";
        User = cfg.user;
        Restart = "always";
        PrivateTmp = true;