1{ config, lib, pkgs, options }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.exporters.nextcloud;
7in
8{
9 port = 9205;
10 extraOpts = {
11 url = mkOption {
12 type = types.str;
13 example = "https://domain.tld";
14 description = ''
15 URL to the Nextcloud serverinfo page.
16 Adding the path to the serverinfo API is optional, it defaults
17 to <literal>/ocs/v2.php/apps/serverinfo/api/v1/info</literal>.
18 '';
19 };
20 username = mkOption {
21 type = types.str;
22 default = "nextcloud-exporter";
23 description = ''
24 Username for connecting to Nextcloud.
25 Note that this account needs to have admin privileges in Nextcloud.
26 '';
27 };
28 passwordFile = mkOption {
29 type = types.path;
30 example = "/path/to/password-file";
31 description = ''
32 File containing the password for connecting to Nextcloud.
33 Make sure that this file is readable by the exporter user.
34 '';
35 };
36 timeout = mkOption {
37 type = types.str;
38 default = "5s";
39 description = ''
40 Timeout for getting server info document.
41 '';
42 };
43 };
44 serviceOpts = {
45 serviceConfig = {
46 DynamicUser = false;
47 ExecStart = ''
48 ${pkgs.prometheus-nextcloud-exporter}/bin/nextcloud-exporter \
49 --addr ${cfg.listenAddress}:${toString cfg.port} \
50 --username ${cfg.username} \
51 --timeout ${cfg.timeout} \
52 --server ${cfg.url} \
53 --password ${escapeShellArg "@${cfg.passwordFile}"} \
54 ${concatStringsSep " \\\n " cfg.extraFlags}
55 '';
56 };
57 };
58}