feat: add very simple nixos module

This commit is contained in:
sinavir 2024-04-18 18:19:59 +02:00
parent 12b4168309
commit 0c6aa5730a
3 changed files with 57 additions and 1 deletions

View file

@ -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;
}

31
nixos/module.nix Normal file
View file

@ -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;
};
}

16
tests/testmodule.nix Normal file
View file

@ -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