feat: Add auto deployment service

This commit is contained in:
sinavir 2024-04-21 20:35:18 +02:00
parent b5f06dc7ef
commit 8e32135aaa
2 changed files with 50 additions and 19 deletions

View file

@ -37,14 +37,16 @@ rec {
fromHive { fromHive {
builder = ( builder = (
node: module: { node: module: {
monitors = let monitors =
hostname = mkHost node module.config; let
in { hostname = mkHost node module.config;
${prefix + hostname} = { in
type = "ping"; {
inherit tags hostname; ${prefix + hostname} = {
type = "ping";
inherit tags hostname;
};
}; };
};
} }
); );
inherit nodes excludes; inherit nodes excludes;

View file

@ -14,10 +14,18 @@ in
json = lib.mkOption { type = lib.types.package; }; json = lib.mkOption { type = lib.types.package; };
script = lib.mkOption { type = lib.types.package; }; script = lib.mkOption { type = lib.types.package; };
}; };
enableService = lib.mkEnableOption "the auto-deployment systemd unit";
host = lib.mkOption { host = lib.mkOption {
default = null; default = null;
type = with lib.types; nullOr str; 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 { extraFlags = lib.mkOption {
default = [ ]; default = [ ];
example = [ "--scrape-http-keywords" ]; example = [ "--scrape-http-keywords" ];
@ -46,18 +54,39 @@ in
}; };
}; };
}; };
config.statelessUptimeKuma = { config = {
lib = import ../lib { inherit lib; }; statelessUptimeKuma = {
extraFlags = lib.optional (cfg.host != null) "--host ${cfg.host}"; lib = import ../lib { inherit lib; };
build = { extraFlags =
json = probesFormat.generate "probes.json" cfg.probesConfig; lib.optional (cfg.host != null) "--host ${cfg.host}"
script = pkgs.writeShellApplication { ++ lib.optional (cfg.username != null) "--username ${cfg.username}";
name = "deploy-uptime-kuma-probes"; build = {
runtimeInputs = [ pkgs.statelessUptimeKuma ]; json = probesFormat.generate "probes.json" cfg.probesConfig;
text = '' script = pkgs.writeShellApplication {
args=("$@") name = "deploy-uptime-kuma-probes";
stateless-uptime-kuma apply-json -f ${cfg.build.json} ${builtins.concatStringsSep " " cfg.extraFlags} "''${args[@]}" 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" ];
script = ''
UPTIME_KUMA_PASSWORD=$(cat $CREDENTIALS_DIRECTORY/password) ${lib.getExe config.statelessUptimeKuma.build.script}
'';
serviceConfig = {
LoadCredential = "password:${cfg.passwordFile}";
Type = "oneshot";
}; };
}; };
}; };