1{
2 config,
3 lib,
4 pkgs,
5 options,
6 ...
7}:
8
9let
10 cfg = config.services.prometheus.exporters.nextcloud;
11 inherit (lib)
12 mkOption
13 types
14 escapeShellArg
15 concatStringsSep
16 ;
17in
18{
19 port = 9205;
20 extraOpts = {
21 url = mkOption {
22 type = types.str;
23 example = "https://domain.tld";
24 description = ''
25 URL to the Nextcloud serverinfo page.
26 Adding the path to the serverinfo API is optional, it defaults
27 to `/ocs/v2.php/apps/serverinfo/api/v1/info`.
28 '';
29 };
30 username = mkOption {
31 type = types.str;
32 default = "nextcloud-exporter";
33 description = ''
34 Username for connecting to Nextcloud.
35 Note that this account needs to have admin privileges in Nextcloud.
36 Unused when using token authentication.
37 '';
38 };
39 passwordFile = mkOption {
40 type = types.nullOr types.path;
41 default = null;
42 example = "/path/to/password-file";
43 description = ''
44 File containing the password for connecting to Nextcloud.
45 Make sure that this file is readable by the exporter user.
46 '';
47 };
48 tokenFile = mkOption {
49 type = types.nullOr types.path;
50 default = null;
51 example = "/path/to/token-file";
52 description = ''
53 File containing the token for connecting to Nextcloud.
54 Make sure that this file is readable by the exporter user.
55 '';
56 };
57 timeout = mkOption {
58 type = types.str;
59 default = "5s";
60 description = ''
61 Timeout for getting server info document.
62 '';
63 };
64 };
65 serviceOpts = {
66 serviceConfig = {
67 DynamicUser = false;
68 ExecStart = ''
69 ${pkgs.prometheus-nextcloud-exporter}/bin/nextcloud-exporter \
70 --addr ${cfg.listenAddress}:${toString cfg.port} \
71 --timeout ${cfg.timeout} \
72 --server ${cfg.url} \
73 ${
74 if cfg.passwordFile != null then
75 ''
76 --username ${cfg.username} \
77 --password ${escapeShellArg "@${cfg.passwordFile}"} \
78 ''
79 else
80 ''
81 --auth-token ${escapeShellArg "@${cfg.tokenFile}"} \
82 ''
83 } \
84 ${concatStringsSep " \\\n " cfg.extraFlags}'';
85 };
86 };
87}