From c4dfae1833ffed63d2a6352148ff7828aca31519 Mon Sep 17 00:00:00 2001 From: sinavir Date: Thu, 18 Apr 2024 19:36:28 +0200 Subject: [PATCH] feat: add script to module --- nixos/module.nix | 26 +++++++++++++++++++++----- tests/testmodule.nix | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/nixos/module.nix b/nixos/module.nix index e7f1dd0..7c4e43b 100644 --- a/nixos/module.nix +++ b/nixos/module.nix @@ -10,10 +10,17 @@ let in { options.statelessUptimeKuma = { - build.json = lib.mkOption { - internal = true; - visible = false; - type = lib.types.package; + build = { + json = lib.mkOption { type = lib.types.package; }; + script = lib.mkOption { type = lib.types.package; }; + }; + 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`. + ''; }; probesConfig = { monitors = lib.mkOption { @@ -31,6 +38,15 @@ in }; }; config.statelessUptimeKuma = { - build.json = probesFormat.generate "probes.json" cfg.probesConfig; + build = { + json = probesFormat.generate "probes.json" cfg.probesConfig; + script = pkgs.writeShellApplication { + name = "deploy-uptime-kuma-probes"; + runtimeInputs = [ pkgs.statelessUptimeKuma ]; + text = '' + stateless-uptime-kuma apply-json -f ${cfg.build.json} ${cfg.extraFlags} + ''; + }; + }; }; } diff --git a/tests/testmodule.nix b/tests/testmodule.nix index cc9ae5f..5995ccc 100644 --- a/tests/testmodule.nix +++ b/tests/testmodule.nix @@ -11,4 +11,4 @@ let }; }; in -((import ../. { }).evalModules { modules = [ module ]; }).config.statelessUptimeKuma.build.json +((import ../. { }).evalModules { modules = [ module ]; }).config.statelessUptimeKuma.build