1 { config, lib, pkgs, ... }:
3 cfg = config.services.influxdb;
5 configOptions = lib.recursiveUpdate {
7 bind-address = ":8088";
8 commit-timeout = "50ms";
9 dir = "${cfg.dataDir}/meta";
10 election-timeout = "1s";
11 heartbeat-timeout = "1s";
12 hostname = "localhost";
13 leader-lease-timeout = "500ms";
14 retention-autocreate = true;
18 dir = "${cfg.dataDir}/data";
19 wal-dir = "${cfg.dataDir}/wal";
20 max-wal-size = 104857600;
21 wal-enable-logging = true;
22 wal-flush-interval = "10m";
23 wal-partition-flush-delay = "2s";
27 shard-writer-timeout = "5s";
33 check-interval = "30m";
39 bind-address = ":8086";
40 https-enabled = false;
42 pprof-enabled = false;
43 write-tracing = false;
47 store-enabled = false;
48 store-database = "_internal";
49 store-interval = "10s";
54 bind-address = ":8083";
55 https-enabled = false;
68 typesdb = "${pkgs.collectd-data}/share/collectd/types.db";
69 database = "collectd_db";
70 bind-address = ":25826";
77 continuous_queries = {
80 recompute-previous-n = 2;
81 recompute-no-older-than = "10m";
82 compute-runs-per-interval = 10;
83 compute-no-more-than = "2m";
88 dir = "${cfg.dataDir}/hh";
89 max-size = 1073741824;
92 retry-interval = "1s";
96 configFile = pkgs.runCommandLocal "config.toml" { } ''
97 ${pkgs.buildPackages.remarshal}/bin/remarshal -if json -of toml \
98 < ${pkgs.writeText "config.json" (builtins.toJSON configOptions)} \
108 services.influxdb = {
110 enable = lib.mkOption {
112 description = "Whether to enable the influxdb server";
113 type = lib.types.bool;
116 package = lib.mkPackageOption pkgs "influxdb" { };
118 user = lib.mkOption {
119 default = "influxdb";
120 description = "User account under which influxdb runs";
121 type = lib.types.str;
124 group = lib.mkOption {
125 default = "influxdb";
126 description = "Group under which influxdb runs";
127 type = lib.types.str;
130 dataDir = lib.mkOption {
131 default = "/var/db/influxdb";
132 description = "Data directory for influxd data files.";
133 type = lib.types.path;
136 extraConfig = lib.mkOption {
138 description = "Extra configuration options for influxdb";
139 type = lib.types.attrs;
145 ###### implementation
147 config = lib.mkIf config.services.influxdb.enable {
149 systemd.tmpfiles.rules = [
150 "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
153 systemd.services.influxdb = {
154 description = "InfluxDB Server";
155 wantedBy = [ "multi-user.target" ];
156 after = [ "network.target" ];
158 ExecStart = ''${cfg.package}/bin/influxd -config "${configFile}"'';
161 Restart = "on-failure";
165 scheme = if configOptions.http.https-enabled then "-k https" else "http";
166 bindAddr = (ba: if lib.hasPrefix ":" ba then "127.0.0.1${ba}" else "${ba}")(toString configOptions.http.bind-address);
169 until ${pkgs.curl.bin}/bin/curl -s -o /dev/null ${scheme}://${bindAddr}/ping; do
175 users.users = lib.optionalAttrs (cfg.user == "influxdb") {
177 uid = config.ids.uids.influxdb;
179 description = "Influxdb daemon user";
183 users.groups = lib.optionalAttrs (cfg.group == "influxdb") {
184 influxdb.gid = config.ids.gids.influxdb;