feat: init openwrt-prometheus-exporter module

Signed-off-by: soyouzpanda <soyouzpanda@soyouzpanda.fr>
This commit is contained in:
soyouzpanda 2025-03-01 13:41:08 +01:00
parent 7d5fe03c07
commit 78476aa743
Signed by: ecoppens
GPG key ID: 871893E37A732093
3 changed files with 67 additions and 0 deletions

View file

@ -20,6 +20,7 @@
./mount ./mount
./network ./network
./ntp ./ntp
./openwrt-prometheus-exporter
./outputs.nix ./outputs.nix
./outputs/ext4fs.nix ./outputs/ext4fs.nix
./outputs/initramfs.nix ./outputs/initramfs.nix

View file

@ -0,0 +1,25 @@
{ lib, pkgs, config, ... }:
let
inherit (lib) mkOption types;
inherit (pkgs) liminix;
in {
options = {
system.service.openwrt-prometheus-exporter = mkOption {
type = liminix.lib.types.serviceDefn;
};
};
config = {
system.service.openwrt-prometheus-exporter = liminix.callService ./service.nix {
httpPorts = mkOption {
type = types.listOf types.port;
default = [ ];
};
httpsPorts = mkOption {
type = types.listOf types.port;
default = [ ];
};
};
};
}

View file

@ -0,0 +1,41 @@
{
liminix,
lib,
lua,
luasocket,
uhttpd,
ubus,
openwrt-prometheus-exporter,
luabit,
}:
{ httpPorts, httpsPorts }:
let
inherit (liminix.services) longrun;
mkLuaPath = package: "${package}/share/lua/${lua.luaversion}/?.lua";
mkLuaCPath = package: "${package}/lib/lua/${lua.luaversion}/?.so";
luaPath = lib.concatStringsSep ";" [
"$LUA_PATH"
(mkLuaPath openwrt-prometheus-exporter)
(mkLuaPath luasocket)
];
luaCPath = lib.concatStringsSep ";" [
"$LUA_CPATH"
(mkLuaCPath luasocket)
(mkLuaCPath ubus)
(mkLuaCPath luabit)
];
in longrun {
name = "openwrt-prometheus-exporter";
run = ''
export LD_LIBRARY_PATH=${uhttpd}/lib/:$LD_LIBRARY_PATH
export LUA_CPATH="${luaCPath}"
export LUA_PATH="${luaPath}"
${uhttpd}/bin/uhttpd -f -c /dev/null -l / -L ${openwrt-prometheus-exporter}/bin/openwrt-prometheus-exporter \
${lib.concatStringsSep " " (lib.map (port: "-p ${toString port}") httpPorts)} \
${lib.concatStringsSep " " (lib.map (port: "-s ${toString port}") httpsPorts)}
'';
}