stateless-uptime-kuma/nixos/module.nix
Luke Granger-Brown 269c7df40a feat: allow configuring settings
This allows setting a settings attrset in the module, which will then
change that setting to the specified value. This is particularly useful
for e.g. the `entryPage` setting, which you can then make set to a
particular value.

There's an escape hatch for string-valued secrets which live in the
settings, like the Steam API key: string-valued settings can be
specified by using the __FILE suffix on the setting name (e.g.
steamAPIKey__FILE) and then specifying the path to a file instead.
The content of that file will be used as the setting instead.
2024-10-06 20:15:12 +01:00

99 lines
2.8 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
probesFormat = pkgs.formats.json { };
cfg = config.statelessUptimeKuma;
in
{
options.statelessUptimeKuma = {
build = {
json = lib.mkOption { type = lib.types.package; };
script = lib.mkOption { type = lib.types.package; };
};
enableService = lib.mkEnableOption "the auto-deployment systemd unit";
host = lib.mkOption {
default = null;
type = with lib.types; nullOr str;
};
username = lib.mkOption {
default = null;
type = with lib.types; nullOr str;
};
passwordFile = lib.mkOption {
type = with lib.types; nullOr path;
};
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`.
'';
};
lib = lib.mkOption { type = lib.types.raw; };
probesConfig = {
monitors = lib.mkOption {
type = with lib.types; attrsOf probesFormat.type;
default = { };
};
tags = lib.mkOption {
type = with lib.types; attrsOf probesFormat.type;
default = { };
};
notifications = lib.mkOption {
type = with lib.types; attrsOf probesFormat.type;
default = { };
};
status_pages = lib.mkOption {
type = with lib.types; attrsOf probesFormat.type;
default = { };
};
settings = lib.mkOption {
type = with lib.types; probesFormat.type;
default = { };
};
};
};
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" ];
startAt = "daily";
script = ''
UPTIME_KUMA_PASSWORD=$(cat $CREDENTIALS_DIRECTORY/password) ${lib.getExe config.statelessUptimeKuma.build.script}
'';
serviceConfig = {
LoadCredential = "password:${cfg.passwordFile}";
Type = "oneshot";
};
};
};
}