1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 cfg = config.services.prometheus.exporters.bitcoin;
10 inherit (lib) mkOption types;
11in
12{
13 port = 9332;
14 extraOpts = {
15 package = lib.mkPackageOption pkgs "prometheus-bitcoin-exporter" { };
16
17 rpcUser = mkOption {
18 type = types.str;
19 default = "bitcoinrpc";
20 description = ''
21 RPC user name.
22 '';
23 };
24
25 rpcPasswordFile = mkOption {
26 type = types.path;
27 description = ''
28 File containing RPC password.
29 '';
30 };
31
32 rpcScheme = mkOption {
33 type = types.enum [
34 "http"
35 "https"
36 ];
37 default = "http";
38 description = ''
39 Whether to connect to bitcoind over http or https.
40 '';
41 };
42
43 rpcHost = mkOption {
44 type = types.str;
45 default = "localhost";
46 description = ''
47 RPC host.
48 '';
49 };
50
51 rpcPort = mkOption {
52 type = types.port;
53 default = 8332;
54 description = ''
55 RPC port number.
56 '';
57 };
58
59 refreshSeconds = mkOption {
60 type = types.ints.unsigned;
61 default = 300;
62 description = ''
63 How often to ask bitcoind for metrics.
64 '';
65 };
66
67 extraEnv = mkOption {
68 type = types.attrsOf types.str;
69 default = { };
70 description = ''
71 Extra environment variables for the exporter.
72 '';
73 };
74 };
75 serviceOpts = {
76 script = ''
77 BITCOIN_RPC_PASSWORD=$(cat ${cfg.rpcPasswordFile})
78 export BITCOIN_RPC_PASSWORD
79 exec ${cfg.package}/bin/bitcoind-monitor.py
80 '';
81
82 environment = {
83 BITCOIN_RPC_USER = cfg.rpcUser;
84 BITCOIN_RPC_SCHEME = cfg.rpcScheme;
85 BITCOIN_RPC_HOST = cfg.rpcHost;
86 BITCOIN_RPC_PORT = toString cfg.rpcPort;
87 METRICS_ADDR = cfg.listenAddress;
88 METRICS_PORT = toString cfg.port;
89 REFRESH_SECONDS = toString cfg.refreshSeconds;
90 }
91 // cfg.extraEnv;
92 };
93}