1{
2 config,
3 lib,
4 pkgs,
5 options,
6 ...
7}:
8
9let
10 cfg = config.services.prometheus.exporters.knot;
11 inherit (lib)
12 mkOption
13 types
14 literalExpression
15 concatStringsSep
16 ;
17in
18{
19 port = 9433;
20 extraOpts = {
21 knotLibraryPath = mkOption {
22 type = types.nullOr types.str;
23 default = null;
24 example = literalExpression ''"''${pkgs.knot-dns.out}/lib/libknot.so"'';
25 description = ''
26 Path to the library of `knot-dns`.
27 '';
28 };
29
30 knotSocketPath = mkOption {
31 type = types.str;
32 default = "/run/knot/knot.sock";
33 description = ''
34 Socket path of {manpage}`knotd(8)`.
35 '';
36 };
37
38 knotSocketTimeout = mkOption {
39 type = types.ints.positive;
40 default = 2000;
41 description = ''
42 Timeout in seconds.
43 '';
44 };
45 };
46 serviceOpts = {
47 path = with pkgs; [
48 procps
49 ];
50 serviceConfig = {
51 ExecStart = ''
52 ${pkgs.prometheus-knot-exporter}/bin/knot-exporter \
53 --web-listen-addr ${cfg.listenAddress} \
54 --web-listen-port ${toString cfg.port} \
55 --knot-socket-path ${cfg.knotSocketPath} \
56 --knot-socket-timeout ${toString cfg.knotSocketTimeout} \
57 ${lib.optionalString (cfg.knotLibraryPath != null) "--knot-library-path ${cfg.knotLibraryPath}"} \
58 ${concatStringsSep " \\\n " cfg.extraFlags}
59 '';
60 SupplementaryGroups = [
61 "knot"
62 ];
63 RestrictAddressFamilies = [
64 # Need AF_UNIX to collect data
65 "AF_UNIX"
66 ];
67 };
68 };
69}