diff --git a/examples/influxdb/.test.sh b/examples/influxdb/.test.sh new file mode 100755 index 000000000..ce2c18335 --- /dev/null +++ b/examples/influxdb/.test.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -ex + +devenv up & +DEVENV_PID=$! +export DEVENV_PID + +function stop() { + pkill -P "$DEVENV_PID" +} + +trap stop EXIT + +# We test for the none-default port, configured in the nix file +timeout 60 bash -c 'until echo > /dev/tcp/localhost/8087; do sleep 0.5; done' + +influx --port 8087 --execute "CREATE DATABASE devenv" +DATABASES=$(influx --port 8087 --execute "SHOW DATABASES" | grep devenv) + +if [[ "$DATABASES" != "devenv" ]]; then + echo "The influxdb database was not created" + exit 1 +fi \ No newline at end of file diff --git a/examples/influxdb/devenv.nix b/examples/influxdb/devenv.nix new file mode 100644 index 000000000..da1ea7081 --- /dev/null +++ b/examples/influxdb/devenv.nix @@ -0,0 +1,74 @@ +{ pkgs, config, ... }: + +let + cfg = config.services.influxdb; +in +{ + packages = [ + pkgs.influxdb + ]; + + services.influxdb.enable = true; + services.influxdb.config = '' + [meta] + dir = "/tmp/influxdb/meta" + + [data] + dir = "/tmp/influxdb/data" + wal-dir = "/tmp/influxdb/wal" + query-log-enabled = true + cache-max-memory-size = 1048576000 + cache-snapshot-memory-size = 26214400 + cache-snapshot-write-cold-duration = "10m" + compact-full-write-cold-duration = "4h" + + [coordinator] + write-timeout = "10s" + max-concurrent-queries = 0 + query-timeout = "0s" + log-queries-after = "0s" + max-select-point = 0 + max-select-series = 0 + max-select-buckets = 0 + + [retention] + enabled = true + check-interval = "30m" + + [shard-precreation] + enabled = true + check-interval = "10m" + advance-period = "30m" + + [monitor] + store-enabled = true + store-database = "_internal" + store-interval = "10s" + + [http] + enabled = true + bind-address = ":8087" + auth-enabled = false + log-enabled = true + write-tracing = false + pprof-enabled = true + https-enabled = false + + [logging] + format = "auto" + level = "info" + suppress-logo = false + + [[graphite]] + enabled = false + + [[collectd]] + enabled = false + + [[opentsdb]] + enabled = false + + [[udp]] + enabled = false + ''; +} diff --git a/examples/influxdb/devenv.yaml b/examples/influxdb/devenv.yaml new file mode 100644 index 000000000..c7cb5ceda --- /dev/null +++ b/examples/influxdb/devenv.yaml @@ -0,0 +1,3 @@ +inputs: + nixpkgs: + url: github:NixOS/nixpkgs/nixpkgs-unstable diff --git a/src/modules/services/influxdb.nix b/src/modules/services/influxdb.nix new file mode 100644 index 000000000..2b42358d8 --- /dev/null +++ b/src/modules/services/influxdb.nix @@ -0,0 +1,28 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.services.influxdb; + types = lib.types; +in +{ + options.services.influxdb = { + enable = lib.mkEnableOption "influxdb"; + + package = lib.mkOption { + type = types.package; + description = "An open-source distributed time series database"; + default = pkgs.influxdb; + defaultText = lib.literalExpression "pkgs.influxdb"; + }; + + config = lib.mkOption { + type = types.lines; + default = ""; + description = "Configuration for InfluxDB-server"; + }; + }; + + config = lib.mkIf cfg.enable { + processes.influxdb-server.exec = "${cfg.package}/bin/influxd -config ${pkgs.writeText "influxdb.conf" cfg.config}"; + }; +}