1 { config, lib, pkgs, ... }:
6 cfg = config.services.kapacitor;
8 kapacitorConf = pkgs.writeTextFile {
9 name = "kapacitord.conf";
11 hostname="${config.networking.hostName}"
12 data_dir="${cfg.dataDir}"
15 bind-address = "${cfg.bind}:${toString cfg.port}"
20 dir = "${cfg.dataDir}/tasks"
21 snapshot-interval = "${cfg.taskSnapshotInterval}"
24 dir = "${cfg.dataDir}/replay"
27 boltdb = "${cfg.dataDir}/kapacitor.db"
29 ${optionalString (cfg.loadDirectory != null) ''
32 dir = "${cfg.loadDirectory}"
35 ${optionalString (cfg.defaultDatabase.enable) ''
40 urls = [ "${cfg.defaultDatabase.url}" ]
41 username = "${cfg.defaultDatabase.username}"
42 password = "${cfg.defaultDatabase.password}"
45 ${optionalString (cfg.alerta.enable) ''
48 url = "${cfg.alerta.url}"
49 token = "${cfg.alerta.token}"
50 environment = "${cfg.alerta.environment}"
51 origin = "${cfg.alerta.origin}"
59 options.services.kapacitor = {
60 enable = mkEnableOption "kapacitor";
64 default = "/var/lib/kapacitor";
65 description = "Location where Kapacitor stores its state";
71 description = "Port of Kapacitor";
78 description = "Address to bind to. The default is to bind to all addresses";
81 extraConfig = mkOption {
82 description = "These lines go into kapacitord.conf verbatim.";
89 default = "kapacitor";
90 description = "User account under which Kapacitor runs";
95 default = "kapacitor";
96 description = "Group under which Kapacitor runs";
99 taskSnapshotInterval = mkOption {
101 description = "Specifies how often to snapshot the task state (in InfluxDB time units)";
105 loadDirectory = mkOption {
106 type = types.nullOr types.path;
107 description = "Directory where to load services from, such as tasks, templates and handlers (or null to disable service loading on startup)";
112 enable = mkEnableOption "kapacitor.defaultDatabase";
115 description = "The URL to an InfluxDB server that serves as the default database";
116 example = "http://localhost:8086";
120 username = mkOption {
121 description = "The username to connect to the remote InfluxDB server";
125 password = mkOption {
126 description = "The password to connect to the remote InfluxDB server";
132 enable = mkEnableOption "kapacitor alerta integration";
135 description = "The URL to the Alerta REST API";
136 default = "http://localhost:5000";
141 description = "Default Alerta authentication token";
146 environment = mkOption {
147 description = "Default Alerta environment";
149 default = "Production";
153 description = "Default origin of alert";
155 default = "kapacitor";
160 config = mkIf cfg.enable {
161 environment.systemPackages = [ pkgs.kapacitor ];
163 systemd.tmpfiles.settings."10-kapacitor".${cfg.dataDir}.d = {
164 inherit (cfg) user group;
167 systemd.services.kapacitor = {
168 description = "Kapacitor Real-Time Stream Processing Engine";
169 wantedBy = [ "multi-user.target" ];
170 after = [ "networking.target" ];
172 ExecStart = "${pkgs.kapacitor}/bin/kapacitord -config ${kapacitorConf}";
178 users.users.kapacitor = {
179 uid = config.ids.uids.kapacitor;
180 description = "Kapacitor user";
184 users.groups.kapacitor = {
185 gid = config.ids.gids.kapacitor;