1{ config, lib, pkgs, options }: 2 3with lib; 4 5let 6 cfg = config.services.prometheus.exporters.nginxlog; 7in { 8 port = 9117; 9 extraOpts = { 10 settings = mkOption { 11 type = types.attrs; 12 default = {}; 13 description = lib.mdDoc '' 14 All settings of nginxlog expressed as an Nix attrset. 15 16 Check the official documentation for the corresponding YAML 17 settings that can all be used here: https://github.com/martin-helmich/prometheus-nginxlog-exporter 18 19 The `listen` object is already generated by `port`, `listenAddress` and `metricsEndpoint` and 20 will be merged with the value of `settings` before writing it as JSON. 21 ''; 22 }; 23 24 metricsEndpoint = mkOption { 25 type = types.str; 26 default = "/metrics"; 27 description = lib.mdDoc '' 28 Path under which to expose metrics. 29 ''; 30 }; 31 }; 32 33 serviceOpts = let 34 listenConfig = { 35 listen = { 36 port = cfg.port; 37 address = cfg.listenAddress; 38 metrics_endpoint = cfg.metricsEndpoint; 39 }; 40 }; 41 completeConfig = pkgs.writeText "nginxlog-exporter.yaml" (builtins.toJSON (lib.recursiveUpdate listenConfig cfg.settings)); 42 in { 43 serviceConfig = { 44 ExecStart = '' 45 ${pkgs.prometheus-nginxlog-exporter}/bin/prometheus-nginxlog-exporter -config-file ${completeConfig} 46 ''; 47 Restart="always"; 48 ProtectSystem="full"; 49 }; 50 }; 51}