diff --git a/default.nix b/default.nix index 0eb205a..f9e996a 100644 --- a/default.nix +++ b/default.nix @@ -6,7 +6,16 @@ rec { shell = pkgs.mkShell { packages = [ python + pkgs.ruff ]; }; - python = pkgs.python3.withPackages (ps: [ ps.click ps.click-log ps.uptime-kuma-api ]); + python = pkgs.python3.withPackages (ps: [ ps.mypy ps.click ps.click-log ps.uptime-kuma-api ]); + evalModules = (pkgs.lib.evalModules { + modules = [ + ./nixos/module.nix + ({ lib, ... }: { + _module.args.pkgs = lib.mkDefault pkgs; + }) + ]; + }).extendModules; } diff --git a/nixos/module.nix b/nixos/module.nix new file mode 100644 index 0000000..144d248 --- /dev/null +++ b/nixos/module.nix @@ -0,0 +1,31 @@ +{ config, lib, pkgs, ... }: +let + probesFormat = pkgs.formats.json {}; + cfg = config.statelessUptimeKuma; +in +{ + options.statelessUptimeKuma = { + build.json = lib.mkOption { + internal = true; + visible = false; + type = lib.types.package; + }; + probesConfig = { + monitors = lib.mkOption { + inherit (probesFormat) type; + default = []; + }; + tags = lib.mkOption { + inherit (probesFormat) type; + default = []; + }; + notifications = lib.mkOption { + inherit (probesFormat) type; + default = []; + }; + }; + }; + config.statelessUptimeKuma = { + build.json = probesFormat.generate "probes.json" cfg.probesConfig; + }; +} diff --git a/tests/testmodule.nix b/tests/testmodule.nix new file mode 100644 index 0000000..8b1fef0 --- /dev/null +++ b/tests/testmodule.nix @@ -0,0 +1,16 @@ +let + module = { + statelessUptimeKuma.probesConfig = { + monitors = [ + { + name = "Nix probe"; + type = "ping"; + hostname = "localhost"; + } + ]; + }; + }; +in +((import ../. {}).evalModules { + modules = [ module ]; +}).config.statelessUptimeKuma.build.json