1{ config, lib, pkgs, options }:
2
3with lib;
4
5let cfg = config.services.prometheus.exporters.fastly;
6in
7{
8 port = 9118;
9 extraOpts = {
10 debug = mkEnableOption (lib.mdDoc "Debug logging mode for fastly-exporter");
11
12 configFile = mkOption {
13 type = types.nullOr types.path;
14 default = null;
15 description = lib.mdDoc ''
16 Path to a fastly-exporter configuration file.
17 Example one can be generated with `fastly-exporter --config-file-example`.
18 '';
19 example = "./fastly-exporter-config.txt";
20 };
21
22 tokenPath = mkOption {
23 type = types.nullOr types.path;
24 apply = final: if final == null then null else toString final;
25 description = lib.mdDoc ''
26 A run-time path to the token file, which is supposed to be provisioned
27 outside of Nix store.
28 '';
29 };
30 };
31 serviceOpts = {
32 script = ''
33 ${optionalString (cfg.tokenPath != null)
34 "export FASTLY_API_TOKEN=$(cat ${toString cfg.tokenPath})"}
35 ${pkgs.prometheus-fastly-exporter}/bin/fastly-exporter \
36 -listen http://${cfg.listenAddress}:${toString cfg.port}
37 ${optionalString cfg.debug "-debug true"} \
38 ${optionalString (cfg.configFile != null) "-config-file ${cfg.configFile}"}
39 '';
40 };
41}