diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..8d457ff --- /dev/null +++ b/module.nix @@ -0,0 +1,33 @@ +{config, lib, pkgs, ...}: +{ + options.printer_scraping = { + enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Enable the script to pull data from the printer" + }; + timer = lib.mkOption { + type = lib.types.string; + default = "1m"; + description = "systemd timer for script execution"; + }; + }; + + config = lib.mkIf config.printer_scraping.enable { + systemd.services."printer-scraping" = { + description = "Pull printer stats and upload to influxdb"; + serviceConfig.Type = "oneshot"; + path = with pkgs; [yq curl]; + script = "exec ${./pull_info.sh}"; + }; + systemd.timers."printer-scraping" = { + wantedBy = ["timers.target"]; + timerConfig = { + OnBootSec = "60s"; + OnUnitActiveSec = config.printer_scraping.timer; + Unit = "printer-scraping.service"; + }; + }; + services.prometheus.pushgateway.enable = true; #Im not dealing with influx + }; +} \ No newline at end of file