Unverified Commit 7bffbf3c authored by Jakob Klepp's avatar Jakob Klepp Committed by GitHub
Browse files

nixos/nats: add option validateConfig (#387048)

As discussed in the comments of https://github.com/NixOS/nixpkgs/pull/322035
and in the issue https://github.com/NixOS/nixpkgs/issues/333119
config validation fails at build time when the config
references files unavailable during build time

nixos/nats: nixfmt 'nixos/modules/services/networking/nats.nix'
parent d471c11d
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -13,8 +13,6 @@ let

  format = pkgs.formats.json { };

  configFile = format.generate "nats.conf" cfg.settings;

  validateConfig =
    file:
    pkgs.callPackage (
@@ -28,6 +26,11 @@ let
          ln -s "${configFile}" "$out"
        ''
    ) { };

  unvalidatedConfigFile = format.generate "nats.conf" cfg.settings;

  configFile =
    if cfg.validateConfig then validateConfig unvalidatedConfigFile else unvalidatedConfigFile;
in
{

@@ -99,6 +102,16 @@ in
          NATS documentation](https://docs.nats.io/nats-server/configuration) for a list of options.
        '';
      };

      validateConfig = mkOption {
        type = types.bool;
        default = true;
        description = ''
          If true, validate nats config at build time. When the config can't
          be checked during build time, for example when it includes other
          files, disable this option.
        '';
      };
    };
  };

@@ -123,7 +136,7 @@ in
        })
        {
          Type = "simple";
          ExecStart = "${pkgs.nats-server}/bin/nats-server -c ${validateConfig configFile}";
          ExecStart = "${pkgs.nats-server}/bin/nats-server -c ${configFile}";
          ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
          ExecStop = "${pkgs.coreutils}/bin/kill -SIGINT $MAINPID";
          Restart = "on-failure";