1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.services.prometheus.exporters.dnssec;
9 configFormat = pkgs.formats.toml { };
10 configFile = configFormat.generate "dnssec-checks.toml" cfg.configuration;
11in
12{
13 port = 9204;
14 extraOpts = {
15 configuration = lib.mkOption {
16 type = lib.types.nullOr lib.types.attrs;
17 default = null;
18 description = ''
19 dnssec exporter configuration as nix attribute set.
20
21 See <https://github.com/chrj/prometheus-dnssec-exporter/blob/master/README.md>
22 for the description of the configuration file format.
23 '';
24 example = lib.literalExpression ''
25 {
26 records = [
27 {
28 zone = "ietf.org";
29 record = "@";
30 type = "SOA";
31 }
32 {
33 zone = "verisigninc.com";
34 record = "@";
35 type = "SOA";
36 }
37 ];
38 }
39 '';
40 };
41
42 listenAddress = lib.mkOption {
43 type = lib.types.nullOr lib.types.str;
44 default = null;
45 description = ''
46 Listen address as host IP and port definition.
47 '';
48 example = ":9204";
49 };
50
51 resolvers = lib.mkOption {
52 type = lib.types.listOf lib.types.str;
53 default = [ ];
54 description = ''
55 DNSSEC capable resolver to be used for the check.
56 '';
57 example = [ "0.0.0.0:53" ];
58 };
59
60 timeout = lib.mkOption {
61 type = lib.types.nullOr lib.types.str;
62 default = null;
63 description = ''
64 DNS request timeout duration.
65 '';
66 example = "10s";
67 };
68
69 extraFlags = lib.mkOption {
70 type = lib.types.listOf lib.types.str;
71 default = [ ];
72 description = ''
73 Extra commandline options when launching Prometheus.
74 '';
75 };
76 };
77
78 serviceOpts = {
79 serviceConfig =
80 let
81 startScript = pkgs.writeShellScriptBin "prometheus-dnssec-exporter-start" "${lib.concatStringsSep
82 " "
83 (
84 [ "${pkgs.prometheus-dnssec-exporter}/bin/prometheus-dnssec-exporter" ]
85 ++ lib.optionals (cfg.configuration != null) [ "-config ${configFile}" ]
86 ++ lib.optionals (cfg.listenAddress != null) [
87 "-listen-address ${lib.escapeShellArg cfg.listenAddress}"
88 ]
89 ++ lib.optionals (cfg.resolvers != [ ]) [
90 "-resolvers ${lib.escapeShellArg (lib.concatStringsSep "," cfg.resolvers)}"
91 ]
92 ++ lib.optionals (cfg.timeout != null) [ "-timeout ${lib.escapeShellArg cfg.timeout}" ]
93 ++ cfg.extraFlags
94 )
95 }";
96 in
97 {
98 ExecStart = lib.getExe startScript;
99 };
100 };
101}