about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/goss.nix
blob: 1b973bbbf45ccdd8c4db047c6caaf19eb99e9990 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{ config, lib, pkgs, ... }:

let
  cfg = config.services.goss;

  settingsFormat = pkgs.formats.yaml { };
  configFile = settingsFormat.generate "goss.yaml" cfg.settings;

in {
  meta = {
    doc = ./goss.md;
    maintainers = [ lib.maintainers.anthonyroussel ];
  };

  options = {
    services.goss = {
      enable = lib.mkEnableOption (lib.mdDoc "Goss daemon");

      package = lib.mkPackageOption pkgs "goss" { };

      environment = lib.mkOption {
        type = lib.types.attrsOf lib.types.str;
        default = { };
        example = {
          GOSS_FMT = "json";
          GOSS_LOGLEVEL = "FATAL";
          GOSS_LISTEN = ":8080";
        };
        description = lib.mdDoc ''
          Environment variables to set for the goss service.

          See <https://github.com/goss-org/goss/blob/master/docs/manual.md>
        '';
      };

      settings = lib.mkOption {
        type = lib.types.submodule { freeformType = settingsFormat.type; };
        default = { };
        example = {
          addr."tcp://localhost:8080" = {
            reachable = true;
            local-address = "127.0.0.1";
          };
          service.goss = {
            enabled = true;
            running = true;
          };
        };
        description = lib.mdDoc ''
          The global options in `config` file in yaml format.

          Refer to <https://github.com/goss-org/goss/blob/master/docs/goss-json-schema.yaml> for schema.
        '';
      };
    };
  };

  config = lib.mkIf cfg.enable {
    environment.systemPackages = [ cfg.package ];

    systemd.services.goss = {
      description = "Goss - Quick and Easy server validation";
      unitConfig.Documentation = "https://github.com/goss-org/goss/blob/master/docs/manual.md";

      after = [ "network-online.target" ];
      wantedBy = [ "multi-user.target" ];
      wants = [ "network-online.target" ];

      environment = {
        GOSS_FILE = configFile;
      } // cfg.environment;

      reloadTriggers = [ configFile ];

      serviceConfig = {
        DynamicUser = true;
        ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
        ExecStart = "${cfg.package}/bin/goss serve";
        Group = "goss";
        Restart = "on-failure";
        RestartSec = 5;
        User = "goss";
      };
    };
  };
}