1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8let 9 cfg = config.services.prometheus.exporters.klipper; 10 inherit (lib) 11 mkOption 12 mkMerge 13 mkIf 14 types 15 concatStringsSep 16 any 17 optionalString 18 ; 19 moonraker = config.services.moonraker; 20in 21{ 22 port = 9101; 23 extraOpts = { 24 package = lib.mkPackageOption pkgs "prometheus-klipper-exporter" { }; 25 26 moonrakerApiKey = mkOption { 27 type = types.str; 28 default = ""; 29 description = '' 30 API Key to authenticate with the Moonraker APIs. 31 Only needed if the host running the exporter is not a trusted client to Moonraker. 32 ''; 33 }; 34 }; 35 serviceOpts = mkMerge ( 36 [ 37 { 38 serviceConfig = { 39 ExecStart = concatStringsSep " " [ 40 "${cfg.package}/bin/prometheus-klipper-exporter" 41 (optionalString (cfg.moonrakerApiKey != "") "--moonraker.apikey ${cfg.moonrakerApiKey}") 42 "--web.listen-address ${cfg.listenAddress}:${toString cfg.port}" 43 "${concatStringsSep " " cfg.extraFlags}" 44 ]; 45 }; 46 } 47 ] 48 ++ [ 49 (mkIf config.services.moonraker.enable { 50 after = [ "moonraker.service" ]; 51 requires = [ "moonraker.service" ]; 52 }) 53 ] 54 ); 55}