mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
chore(ci): flake update
gatus module upstreamed
This commit is contained in:
parent
d04959b11a
commit
07228a1a1f
3 changed files with 262 additions and 206 deletions
6
flake.lock
generated
6
flake.lock
generated
|
|
@ -190,11 +190,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1727802920,
|
"lastModified": 1728018373,
|
||||||
"narHash": "sha256-HP89HZOT0ReIbI7IJZJQoJgxvB2Tn28V6XS3MNKnfLs=",
|
"narHash": "sha256-NOiTvBbRLIOe5F6RbHaAh6++BNjsb149fGZd1T4+KBg=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "27e30d177e57d912d614c88c622dcfdb2e6e6515",
|
"rev": "bc947f541ae55e999ffdb4013441347d83b00feb",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -5,53 +5,22 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.options) mkOption mkEnableOption mkPackageOption;
|
inherit (lib.options) mkOption mkEnableOption mkPackageOption;
|
||||||
inherit (lib.modules) mkIf mkOptionDefault;
|
inherit (lib.modules) mkIf mkMerge mkForce;
|
||||||
inherit (lib.attrsets) attrValues;
|
inherit (lib.attrsets) attrValues;
|
||||||
inherit (lib.lists) length unique;
|
inherit (lib.lists) length unique;
|
||||||
inherit (lib) types;
|
inherit (lib) types;
|
||||||
|
|
||||||
cfg = config.services.gatus;
|
cfg' = config.services.gatus';
|
||||||
|
|
||||||
configFile = pkgs.writeText "gatus-config.yml" (builtins.toJSON (cfg.settings
|
configFile = pkgs.writeText "gatus-config.yml" (builtins.toJSON (cfg'.settings
|
||||||
// {
|
// {
|
||||||
endpoints = builtins.attrValues cfg.settings.endpoints;
|
endpoints = builtins.attrValues cfg'.settings.endpoints;
|
||||||
}));
|
}));
|
||||||
in {
|
endpointModule = {name, lib, ...}: let
|
||||||
options.services.gatus = {
|
inherit (lib) types;
|
||||||
enable = mkEnableOption "a developer-oriented service status page";
|
inherit (lib.options) mkOption mkEnableOption;
|
||||||
|
inherit (lib.modules) mkOptionDefault;
|
||||||
package = mkPackageOption pkgs "gatus" {};
|
in {
|
||||||
|
|
||||||
user = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = "gatus";
|
|
||||||
};
|
|
||||||
|
|
||||||
group = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = "gatus";
|
|
||||||
};
|
|
||||||
|
|
||||||
environmentFile = mkOption {
|
|
||||||
type = types.nullOr types.path;
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
# https://github.com/TwiN/gatus#configuration
|
|
||||||
|
|
||||||
settings = {
|
|
||||||
debug = mkEnableOption "debug logs";
|
|
||||||
|
|
||||||
metrics = mkEnableOption "expose metrics at /metrics";
|
|
||||||
|
|
||||||
storage = {
|
|
||||||
path = mkOption {type = types.path;};
|
|
||||||
type = mkOption {type = types.enum ["memory" "sqlite" "postgres"];};
|
|
||||||
caching = mkEnableOption "write-through caching";
|
|
||||||
};
|
|
||||||
|
|
||||||
endpoints = mkOption {
|
|
||||||
type = types.attrsOf (types.submodule ({name, ...}: {
|
|
||||||
options = {
|
options = {
|
||||||
enabled = mkOption {
|
enabled = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
|
|
@ -231,8 +200,71 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {name = mkOptionDefault name;};
|
config = {
|
||||||
}));
|
name = mkOptionDefault name;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
options.services.gatus = let
|
||||||
|
settingsModule = { ... }: {
|
||||||
|
options = with types; {
|
||||||
|
endpoints = mkOption {
|
||||||
|
type = listOf unspecified;
|
||||||
|
#type = attrsOf (submodule endpointModule);
|
||||||
|
#default = {};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in with types; {
|
||||||
|
user = mkOption {
|
||||||
|
type = nullOr str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
endpoints = mkOption {
|
||||||
|
type = attrsOf (submodule endpointModule);
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
settings = mkOption {
|
||||||
|
type = submodule settingsModule;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
options.services.gatus' = {
|
||||||
|
enable = mkEnableOption "a developer-oriented service status page";
|
||||||
|
|
||||||
|
package = mkPackageOption pkgs "gatus" {};
|
||||||
|
|
||||||
|
user = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "gatus";
|
||||||
|
};
|
||||||
|
|
||||||
|
group = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "gatus";
|
||||||
|
};
|
||||||
|
|
||||||
|
environmentFile = mkOption {
|
||||||
|
type = types.nullOr types.path;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
# https://github.com/TwiN/gatus#configuration
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
debug = mkEnableOption "debug logs";
|
||||||
|
|
||||||
|
metrics = mkEnableOption "expose metrics at /metrics";
|
||||||
|
|
||||||
|
storage = {
|
||||||
|
path = mkOption {type = types.path;};
|
||||||
|
type = mkOption {type = types.enum ["memory" "sqlite" "postgres"];};
|
||||||
|
caching = mkEnableOption "write-through caching";
|
||||||
|
};
|
||||||
|
|
||||||
|
endpoints = mkOption {
|
||||||
|
type = types.attrsOf (types.submodule endpointModule);
|
||||||
default = {};
|
default = {};
|
||||||
};
|
};
|
||||||
alerting = mkOption {
|
alerting = mkOption {
|
||||||
|
|
@ -310,8 +342,8 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = let
|
||||||
systemd.services.gatus = {
|
conf'.systemd.services.gatus = {
|
||||||
description = "Automated developer-oriented status page";
|
description = "Automated developer-oriented status page";
|
||||||
after = ["network.target"];
|
after = ["network.target"];
|
||||||
wantedBy = ["multi-user.target"];
|
wantedBy = ["multi-user.target"];
|
||||||
|
|
@ -321,12 +353,12 @@ in {
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
User = cfg.user;
|
User = cfg'.user;
|
||||||
Group = cfg.group;
|
Group = cfg'.group;
|
||||||
StateDirectory = "gatus";
|
StateDirectory = "gatus";
|
||||||
LogsDirectory = "gatus";
|
LogsDirectory = "gatus";
|
||||||
EnvironmentFile =
|
EnvironmentFile =
|
||||||
mkIf (cfg.environmentFile != null) [cfg.environmentFile];
|
mkIf (cfg'.environmentFile != null) [cfg'.environmentFile];
|
||||||
|
|
||||||
AmbientCapabilities = ["CAP_NET_RAW"]; # needed for ICMP probes
|
AmbientCapabilities = ["CAP_NET_RAW"]; # needed for ICMP probes
|
||||||
DevicePolicy = "closed";
|
DevicePolicy = "closed";
|
||||||
|
|
@ -354,29 +386,42 @@ in {
|
||||||
UMask = "0077";
|
UMask = "0077";
|
||||||
|
|
||||||
ExecStart = [
|
ExecStart = [
|
||||||
(lib.getExe cfg.package)
|
(lib.getExe cfg'.package)
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
users.groups = mkIf (cfg.group == "gatus") {${cfg.group} = {};};
|
conf'.users.groups = mkIf (cfg'.group == "gatus") {${cfg'.group} = {};};
|
||||||
|
|
||||||
users.users = mkIf (cfg.user == "gatus") {
|
conf'.users.users = mkIf (cfg'.user == "gatus") {
|
||||||
${cfg.user} = {
|
${cfg'.user} = {
|
||||||
inherit (cfg) group;
|
inherit (cfg') group;
|
||||||
description = "gatus service user";
|
description = "gatus service user";
|
||||||
isSystemUser = true;
|
isSystemUser = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
assertions = let
|
assertions = endpoints: let
|
||||||
endpointNames = map (endpoint: endpoint.name) (attrValues cfg.settings.endpoints);
|
endpointNames = map (endpoint: endpoint.name) (attrValues endpoints);
|
||||||
in [
|
in [
|
||||||
{
|
{
|
||||||
assertion = length (unique endpointNames) == length endpointNames;
|
assertion = length (unique endpointNames) == length endpointNames;
|
||||||
message = "Gatus endpoint names must be unique";
|
message = "Gatus endpoint names must be unique";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
conf'.assertions = assertions cfg'.settings.endpoints;
|
||||||
|
cfg = config.services.gatus;
|
||||||
|
conf.systemd.services.gatus = {
|
||||||
|
serviceConfig.User = mkIf (cfg.user != null) (mkForce cfg.user);
|
||||||
};
|
};
|
||||||
|
conf.assertions = assertions cfg.endpoints;
|
||||||
|
serviceConf = {
|
||||||
|
services.gatus.settings.endpoints = mkIf (cfg.endpoints != {}) (attrValues cfg.endpoints);
|
||||||
|
};
|
||||||
|
in mkMerge [
|
||||||
|
(mkIf cfg'.enable conf')
|
||||||
|
(mkIf cfg.enable conf)
|
||||||
|
serviceConf
|
||||||
|
];
|
||||||
|
|
||||||
meta.maintainers = with lib.maintainers; [christoph-heiss];
|
meta.maintainers = with lib.maintainers; [christoph-heiss];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -174,16 +174,18 @@ in {
|
||||||
};
|
};
|
||||||
services.gatus = {
|
services.gatus = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
user = mkDefault "gatus";
|
||||||
environmentFile = config.sops.secrets.gatus_environment_file.path;
|
environmentFile = config.sops.secrets.gatus_environment_file.path;
|
||||||
|
|
||||||
|
# Endpoint configuration
|
||||||
|
endpoints = listToAttrs (concatMap mapSystem statusSystems);
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
# Environment variables are pulled in to be usable within the config.
|
# Environment variables are pulled in to be usable within the config.
|
||||||
alerting.discord = {
|
alerting.discord = {
|
||||||
webhook-url = "\${DISCORD_WEBHOOK_URL}";
|
webhook-url = "\${DISCORD_WEBHOOK_URL}";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Endpoint configuration
|
|
||||||
endpoints = listToAttrs (concatMap mapSystem statusSystems);
|
|
||||||
|
|
||||||
# The actual status page configuration
|
# The actual status page configuration
|
||||||
ui = {
|
ui = {
|
||||||
title = "Gensokyo Zone Status";
|
title = "Gensokyo Zone Status";
|
||||||
|
|
@ -209,6 +211,15 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
users = mkIf (cfg.enable && cfg.user == "gatus") {
|
||||||
|
groups.gatus = {};
|
||||||
|
users.gatus = {
|
||||||
|
group = "gatus";
|
||||||
|
description = "gatus service user";
|
||||||
|
isSystemUser = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
networking.firewall.interfaces.lan.allowedTCPPorts = mkIf cfg.enable [
|
networking.firewall.interfaces.lan.allowedTCPPorts = mkIf cfg.enable [
|
||||||
cfg.settings.web.port
|
cfg.settings.web.port
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue