8 cfg = config.services.kapacitor;
10 kapacitorConf = pkgs.writeTextFile {
11 name = "kapacitord.conf";
13 hostname="${config.networking.hostName}"
14 data_dir="${cfg.dataDir}"
17 bind-address = "${cfg.bind}:${toString cfg.port}"
22 dir = "${cfg.dataDir}/tasks"
23 snapshot-interval = "${cfg.taskSnapshotInterval}"
26 dir = "${cfg.dataDir}/replay"
29 boltdb = "${cfg.dataDir}/kapacitor.db"
31 ${lib.optionalString (cfg.loadDirectory != null) ''
34 dir = "${cfg.loadDirectory}"
37 ${lib.optionalString (cfg.defaultDatabase.enable) ''
42 urls = [ "${cfg.defaultDatabase.url}" ]
43 username = "${cfg.defaultDatabase.username}"
44 password = "${cfg.defaultDatabase.password}"
47 ${lib.optionalString (cfg.alerta.enable) ''
50 url = "${cfg.alerta.url}"
51 token = "${cfg.alerta.token}"
52 environment = "${cfg.alerta.environment}"
53 origin = "${cfg.alerta.origin}"
61 options.services.kapacitor = {
62 enable = lib.mkEnableOption "kapacitor";
64 dataDir = lib.mkOption {
65 type = lib.types.path;
66 default = "/var/lib/kapacitor";
67 description = "Location where Kapacitor stores its state";
71 type = lib.types.port;
73 description = "Port of Kapacitor";
80 description = "Address to bind to. The default is to bind to all addresses";
83 extraConfig = lib.mkOption {
84 description = "These lines go into kapacitord.conf verbatim.";
86 type = lib.types.lines;
91 default = "kapacitor";
92 description = "User account under which Kapacitor runs";
95 group = lib.mkOption {
97 default = "kapacitor";
98 description = "Group under which Kapacitor runs";
101 taskSnapshotInterval = lib.mkOption {
102 type = lib.types.str;
103 description = "Specifies how often to snapshot the task state (in InfluxDB time units)";
107 loadDirectory = lib.mkOption {
108 type = lib.types.nullOr lib.types.path;
109 description = "Directory where to load services from, such as tasks, templates and handlers (or null to disable service loading on startup)";
114 enable = lib.mkEnableOption "kapacitor.defaultDatabase";
117 description = "The URL to an InfluxDB server that serves as the default database";
118 example = "http://localhost:8086";
119 type = lib.types.str;
122 username = lib.mkOption {
123 description = "The username to connect to the remote InfluxDB server";
124 type = lib.types.str;
127 password = lib.mkOption {
128 description = "The password to connect to the remote InfluxDB server";
129 type = lib.types.str;
134 enable = lib.mkEnableOption "kapacitor alerta integration";
137 description = "The URL to the Alerta REST API";
138 default = "http://localhost:5000";
139 type = lib.types.str;
142 token = lib.mkOption {
143 description = "Default Alerta authentication token";
144 type = lib.types.str;
148 environment = lib.mkOption {
149 description = "Default Alerta environment";
150 type = lib.types.str;
151 default = "Production";
154 origin = lib.mkOption {
155 description = "Default origin of alert";
156 type = lib.types.str;
157 default = "kapacitor";
162 config = lib.mkIf cfg.enable {
163 environment.systemPackages = [ pkgs.kapacitor ];
165 systemd.tmpfiles.settings."10-kapacitor".${cfg.dataDir}.d = {
166 inherit (cfg) user group;
169 systemd.services.kapacitor = {
170 description = "Kapacitor Real-Time Stream Processing Engine";
171 wantedBy = [ "multi-user.target" ];
172 after = [ "networking.target" ];
174 ExecStart = "${pkgs.kapacitor}/bin/kapacitord -config ${kapacitorConf}";
180 users.users.kapacitor = {
181 uid = config.ids.uids.kapacitor;
182 description = "Kapacitor user";
186 users.groups.kapacitor = {
187 gid = config.ids.gids.kapacitor;