From 0c6aa5730a7632ff8789f617cd55a70b287f6be1 Mon Sep 17 00:00:00 2001 From: sinavir Date: Thu, 18 Apr 2024 18:19:59 +0200 Subject: [PATCH] feat: add very simple nixos module --- default.nix | 11 ++++++++++- nixos/module.nix | 31 +++++++++++++++++++++++++++++++ tests/testmodule.nix | 16 ++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 nixos/module.nix create mode 100644 tests/testmodule.nix 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