diff --git a/modules/all-modules.nix b/modules/all-modules.nix index 9afff7d..14aefa0 100644 --- a/modules/all-modules.nix +++ b/modules/all-modules.nix @@ -20,6 +20,7 @@ ./mount ./network ./ntp + ./openwrt-prometheus-exporter ./outputs.nix ./outputs/ext4fs.nix ./outputs/initramfs.nix diff --git a/modules/openwrt-prometheus-exporter/default.nix b/modules/openwrt-prometheus-exporter/default.nix new file mode 100644 index 0000000..4735b5b --- /dev/null +++ b/modules/openwrt-prometheus-exporter/default.nix @@ -0,0 +1,35 @@ +{ 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 { + package = mkOption { + type = types.package; + default = pkgs.openwrt-prometheus-exporter; + }; + + uhttpdPackage = mkOption { + type = types.package; + default = pkgs.uhttpd; + }; + + httpPorts = mkOption { + type = types.listOf types.port; + default = [ ]; + }; + + httpsPorts = mkOption { + type = types.listOf types.port; + default = [ ]; + }; + }; + }; +} diff --git a/modules/openwrt-prometheus-exporter/service.nix b/modules/openwrt-prometheus-exporter/service.nix new file mode 100644 index 0000000..9101d9c --- /dev/null +++ b/modules/openwrt-prometheus-exporter/service.nix @@ -0,0 +1,16 @@ +{ + liminix, + writeText, + lib, +}: +{ package, uhttpdPackage, httpPorts, httpsPorts }: +let + inherit (liminix.services) longrun; +in longrun { + name = "openwrt-prometheus-exporter"; + run = '' + ${uhttpdPackage}/bin/uhttpd -f -c /dev/null -l / -L ${package}/bin/openwrt-prometheus-exporter \ + ${lib.concatStringsSep " " (lib.map (port: "-p ${toString port}") httpPorts)} \ + ${lib.concatStringsSep " " (lib.map (port: "-s ${toString port}") httpsPorts)} + ''; +}