1 { config, lib, pkgs, options, ... }:
4 cfg = config.services.prometheus.exporters.imap-mailstat;
6 if (builtins.typeOf value == "string") then "\"${value}\""
8 if (builtins.typeOf value == "int") then "${toString value}"
10 if (builtins.typeOf value == "bool") then (if value then "true" else "false")
11 else "XXX ${toString value}"
23 createConfigFile = accounts:
24 # unfortunately on toTOML yet
25 # https://github.com/NixOS/nix/issues/3929
26 pkgs.writeText "imap-mailstat-exporter.conf" ''
27 ${concatStrings (attrValues (mapAttrs (name: config: "[[Accounts]]\nname = \"${name}\"\n${concatStrings (attrValues (mapAttrs (k: v: "${k} = ${valueToString v}\n") config))}") accounts))}
29 mkOpt = type: description: mkOption {
30 type = types.nullOr type;
32 description = description;
34 accountOptions.options = {
35 mailaddress = mkOpt types.str "Your email address (at the moment used as login name)";
36 username = mkOpt types.str "If empty string mailaddress value is used";
37 password = mkOpt types.str "";
38 serveraddress = mkOpt types.str "mailserver name or address";
39 serverport = mkOpt types.int "imap port number (at the moment only tls connection is supported)";
40 starttls = mkOpt types.bool "set to true for using STARTTLS to start a TLS connection";
46 oldestUnseenDate = mkOption {
50 Enable metric with timestamp of oldest unseen mail
54 type = types.attrsOf (types.submodule accountOptions);
60 configurationFile = mkOption {
62 example = "/path/to/config-file";
64 File containing the configuration
71 ${pkgs.prometheus-imap-mailstat-exporter}/bin/imap-mailstat-exporter \
72 -config ${createConfigFile cfg.accounts} \
73 ${optionalString cfg.oldestUnseenDate "-oldestunseendate"} \
74 ${concatStringsSep " \\\n " cfg.extraFlags}