Unverified Commit 075be3e7 authored by Pol Dellaiera's avatar Pol Dellaiera Committed by GitHub
Browse files

nixos/gatus: init module (#294469)

parents d5a06938 7d68a055
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -16660,6 +16660,12 @@
    githubId = 14542417;
    name = "Sergey Ichtchenko";
  };
  pizzapim = {
    email = "pim@kunis.nl";
    github = "pizzapim";
    githubId = 23135512;
    name = "Pim Kunis";
  };
  pjbarnoy = {
    email = "pjbarnoy@gmail.com";
    github = "waaamb";
+2 −0
Original line number Diff line number Diff line
@@ -120,6 +120,8 @@

- [Localsend](https://localsend.org/), an open source cross-platform alternative to AirDrop. Available as [programs.localsend](#opt-programs.localsend.enable).

- [Gatus](https://github.com/TwiN/gatus), an automated developer-oriented status page. Available as [services.gatus](#opt-services.gatus.enable).

- [cryptpad](https://cryptpad.org/), a privacy-oriented collaborative platform (docs/drive/etc), has been added back. Available as [services.cryptpad](#opt-services.cryptpad.enable).

- [realm](https://github.com/zhboner/realm), a simple, high performance relay server written in rust. Available as [services.realm.enable](#opt-services.realm.enable).
+1 −0
Original line number Diff line number Diff line
@@ -883,6 +883,7 @@
  ./services/monitoring/datadog-agent.nix
  ./services/monitoring/do-agent.nix
  ./services/monitoring/fusion-inventory.nix
  ./services/monitoring/gatus.nix
  ./services/monitoring/goss.nix
  ./services/monitoring/grafana-agent.nix
  ./services/monitoring/grafana-image-renderer.nix
+132 −0
Original line number Diff line number Diff line
{
  pkgs,
  lib,
  config,
  ...
}:
let
  cfg = config.services.gatus;

  settingsFormat = pkgs.formats.yaml { };

  inherit (lib)
    getExe
    literalExpression
    maintainers
    mkEnableOption
    mkIf
    mkOption
    mkPackageOption
    ;

  inherit (lib.types)
    bool
    int
    nullOr
    path
    submodule
    ;
in
{
  options.services.gatus = {
    enable = mkEnableOption "Gatus";

    package = mkPackageOption pkgs "gatus" { };

    configFile = mkOption {
      type = path;
      default = settingsFormat.generate "gatus.yaml" cfg.settings;
      defaultText = literalExpression ''
        let settingsFormat = pkgs.formats.yaml { }; in settingsFormat.generate "gatus.yaml" cfg.settings;
      '';
      description = ''
        Path to the Gatus configuration file.
        Overrides any configuration made using the `settings` option.
      '';
    };

    environmentFile = mkOption {
      type = nullOr path;
      default = null;
      description = ''
        File to load as environment file.
        Environmental variables from this file can be interpolated in the configuration file using `''${VARIABLE}`.
        This is useful to avoid putting secrets into the nix store.
      '';
    };

    settings = mkOption {
      type = submodule {
        freeformType = settingsFormat.type;
        options = {
          web.port = mkOption {
            type = int;
            default = 8080;
            description = ''
              The TCP port to serve the Gatus service at.
            '';
          };
        };
      };

      default = { };

      example = literalExpression ''
        {
          web.port = 8080;
          endpoints = [{
            name = "website";
            url = "https://twin.sh/health";
            interval = "5m";
            conditions = [
              "[STATUS] == 200"
              "[BODY].status == UP"
              "[RESPONSE_TIME] < 300"
            ];
          }];
        }
      '';

      description = ''
        Configuration for Gatus.
        Supported options can be found at the [docs](https://gatus.io/docs).
      '';
    };

    openFirewall = mkOption {
      type = bool;
      default = false;
      description = ''
        Whether to open the firewall for the Gatus web interface.
      '';
    };
  };

  config = mkIf cfg.enable {
    systemd.services.gatus = {
      description = "Automated developer-oriented status page";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

      serviceConfig = {
        DynamicUser = true;
        User = "gatus";
        Group = "gatus";
        Type = "simple";
        Restart = "on-failure";
        ExecStart = getExe cfg.package;
        StateDirectory = "gatus";
        SyslogIdentifier = "gatus";
        EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
      };

      environment = {
        GATUS_CONFIG_PATH = cfg.configFile;
      };
    };

    networking.firewall.allowedTCPPorts = lib.optionals cfg.openFirewall [ cfg.settings.web.port ];
  };

  meta.maintainers = with maintainers; [ pizzapim ];
}
+1 −0
Original line number Diff line number Diff line
@@ -367,6 +367,7 @@ in {
  mimir = handleTest ./mimir.nix {};
  gancio = handleTest ./gancio.nix {};
  garage = handleTest ./garage {};
  gatus = runTest ./gatus.nix;
  gemstash = handleTest ./gemstash.nix {};
  geoserver = runTest ./geoserver.nix;
  gerrit = handleTest ./gerrit.nix {};
Loading