1{
2 config,
3 lib,
4 pkgs,
5 options,
6 ...
7}:
8
9let
10 cfg = config.services.prometheus.exporters.storagebox;
11 inherit (lib) mkPackageOption;
12in
13{
14 port = 9509;
15 extraOpts = {
16 package = mkPackageOption pkgs "prometheus-storagebox-exporter" { };
17 tokenFile = lib.mkOption {
18 type = lib.types.pathWith {
19 inStore = false;
20 absolute = true;
21 };
22 description = "File that contains the Hetzner API token to use.";
23 };
24
25 };
26 serviceOpts = {
27 after = [ "network.target" ];
28 wantedBy = [ "multi-user.target" ];
29 script = ''
30 export HETZNER_TOKEN=$(< "''${CREDENTIALS_DIRECTORY}/token")
31 exec ${lib.getExe cfg.package}
32 '';
33
34 environment = {
35 LISTEN_ADDR = "${toString cfg.listenAddress}:${toString cfg.port}";
36 };
37
38 serviceConfig = {
39 DynamicUser = true;
40 Restart = "always";
41 RestartSec = "10s";
42 LoadCredential = [
43 "token:${cfg.tokenFile}"
44 ];
45 };
46 };
47}