1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 format = pkgs.formats.json { };
7 cfg = config.services.influxdb2;
8 configFile = format.generate "config.json" cfg.settings;
9in
10{
11 options = {
12 services.influxdb2 = {
13 enable = mkEnableOption (lib.mdDoc "the influxdb2 server");
14
15 package = mkOption {
16 default = pkgs.influxdb2-server;
17 defaultText = literalExpression "pkgs.influxdb2";
18 description = lib.mdDoc "influxdb2 derivation to use.";
19 type = types.package;
20 };
21
22 settings = mkOption {
23 default = { };
24 description = lib.mdDoc ''configuration options for influxdb2, see <https://docs.influxdata.com/influxdb/v2.0/reference/config-options> for details.'';
25 type = format.type;
26 };
27 };
28 };
29
30 config = mkIf cfg.enable {
31 assertions = [{
32 assertion = !(builtins.hasAttr "bolt-path" cfg.settings) && !(builtins.hasAttr "engine-path" cfg.settings);
33 message = "services.influxdb2.config: bolt-path and engine-path should not be set as they are managed by systemd";
34 }];
35
36 systemd.services.influxdb2 = {
37 description = "InfluxDB is an open-source, distributed, time series database";
38 documentation = [ "https://docs.influxdata.com/influxdb/" ];
39 wantedBy = [ "multi-user.target" ];
40 after = [ "network.target" ];
41 environment = {
42 INFLUXD_CONFIG_PATH = configFile;
43 ZONEINFO = "${pkgs.tzdata}/share/zoneinfo";
44 };
45 serviceConfig = {
46 ExecStart = "${cfg.package}/bin/influxd --bolt-path \${STATE_DIRECTORY}/influxd.bolt --engine-path \${STATE_DIRECTORY}/engine";
47 StateDirectory = "influxdb2";
48 User = "influxdb2";
49 Group = "influxdb2";
50 CapabilityBoundingSet = "";
51 SystemCallFilter = "@system-service";
52 LimitNOFILE = 65536;
53 KillMode = "control-group";
54 Restart = "on-failure";
55 };
56 };
57
58 users.extraUsers.influxdb2 = {
59 isSystemUser = true;
60 group = "influxdb2";
61 };
62
63 users.extraGroups.influxdb2 = {};
64 };
65
66 meta.maintainers = with lib.maintainers; [ nickcao ];
67}