2024-04-18 18:23:11 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2024-04-18 18:19:59 +02:00
|
|
|
let
|
2024-04-18 18:23:11 +02:00
|
|
|
probesFormat = pkgs.formats.json { };
|
2024-04-18 18:19:59 +02:00
|
|
|
cfg = config.statelessUptimeKuma;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.statelessUptimeKuma = {
|
2024-04-18 19:36:28 +02:00
|
|
|
build = {
|
|
|
|
json = lib.mkOption { type = lib.types.package; };
|
|
|
|
script = lib.mkOption { type = lib.types.package; };
|
|
|
|
};
|
2024-04-21 20:35:18 +02:00
|
|
|
enableService = lib.mkEnableOption "the auto-deployment systemd unit";
|
2024-04-21 11:39:10 +02:00
|
|
|
host = lib.mkOption {
|
|
|
|
default = null;
|
|
|
|
type = with lib.types; nullOr str;
|
|
|
|
};
|
2024-04-21 20:35:18 +02:00
|
|
|
username = lib.mkOption {
|
|
|
|
default = null;
|
|
|
|
type = with lib.types; nullOr str;
|
|
|
|
};
|
|
|
|
passwordFile = lib.mkOption {
|
|
|
|
type = with lib.types; nullOr path;
|
|
|
|
};
|
2024-04-18 19:36:28 +02:00
|
|
|
extraFlags = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
example = [ "--scrape-http-keywords" ];
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Extra arguments to use for executing `stateless-uptime-kuma`.
|
|
|
|
'';
|
2024-04-18 18:19:59 +02:00
|
|
|
};
|
2024-04-18 20:27:17 +02:00
|
|
|
lib = lib.mkOption { type = lib.types.raw; };
|
2024-04-18 18:19:59 +02:00
|
|
|
probesConfig = {
|
|
|
|
monitors = lib.mkOption {
|
2024-04-20 13:37:45 +02:00
|
|
|
type = with lib.types; attrsOf probesFormat.type;
|
|
|
|
default = { };
|
2024-04-18 18:19:59 +02:00
|
|
|
};
|
|
|
|
tags = lib.mkOption {
|
2024-04-20 13:37:45 +02:00
|
|
|
type = with lib.types; attrsOf probesFormat.type;
|
|
|
|
default = { };
|
2024-04-18 18:19:59 +02:00
|
|
|
};
|
|
|
|
notifications = lib.mkOption {
|
2024-04-20 13:37:45 +02:00
|
|
|
type = with lib.types; attrsOf probesFormat.type;
|
|
|
|
default = { };
|
2024-04-18 18:19:59 +02:00
|
|
|
};
|
2024-04-21 11:55:34 +02:00
|
|
|
status_pages = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf probesFormat.type;
|
|
|
|
default = { };
|
|
|
|
};
|
2024-04-18 18:19:59 +02:00
|
|
|
};
|
|
|
|
};
|
2024-04-21 20:35:18 +02:00
|
|
|
config = {
|
|
|
|
statelessUptimeKuma = {
|
|
|
|
lib = import ../lib { inherit lib; };
|
|
|
|
extraFlags =
|
|
|
|
lib.optional (cfg.host != null) "--host ${cfg.host}"
|
|
|
|
++ lib.optional (cfg.username != null) "--username ${cfg.username}";
|
|
|
|
build = {
|
|
|
|
json = probesFormat.generate "probes.json" cfg.probesConfig;
|
|
|
|
script = pkgs.writeShellApplication {
|
|
|
|
name = "deploy-uptime-kuma-probes";
|
|
|
|
runtimeInputs = [ pkgs.statelessUptimeKuma ];
|
|
|
|
text = ''
|
|
|
|
args=("$@")
|
|
|
|
stateless-uptime-kuma apply-json -f ${cfg.build.json} ${builtins.concatStringsSep " " cfg.extraFlags} "''${args[@]}"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.stateless-uptime-kuma = lib.mkIf cfg.enableService {
|
|
|
|
description = "Uptime-kuma probes deployment";
|
|
|
|
|
|
|
|
wants = [ "uptime-kuma.service" ];
|
|
|
|
after = [ "uptime-kuma.service" ];
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
2024-09-29 17:13:17 +02:00
|
|
|
startAt = "daily";
|
|
|
|
|
2024-04-21 20:35:18 +02:00
|
|
|
script = ''
|
|
|
|
UPTIME_KUMA_PASSWORD=$(cat $CREDENTIALS_DIRECTORY/password) ${lib.getExe config.statelessUptimeKuma.build.script}
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
LoadCredential = "password:${cfg.passwordFile}";
|
|
|
|
Type = "oneshot";
|
2024-04-18 19:36:28 +02:00
|
|
|
};
|
|
|
|
};
|
2024-04-18 18:19:59 +02:00
|
|
|
};
|
|
|
|
}
|