1 { config, lib, pkgs, ... }:
2 let cfg = config.services.vector;
6 options.services.vector = {
7 enable = lib.mkEnableOption "Vector, a high-performance observability data pipeline";
9 package = lib.mkPackageOption pkgs "vector" { };
11 journaldAccess = lib.mkOption {
12 type = lib.types.bool;
15 Enable Vector to access journald.
19 settings = lib.mkOption {
20 type = (pkgs.formats.json { }).type;
23 Specify the configuration for Vector in Nix.
28 config = lib.mkIf cfg.enable {
30 environment.systemPackages = [ pkgs.vector ];
32 systemd.services.vector = {
33 description = "Vector event and log aggregator";
34 wantedBy = [ "multi-user.target" ];
35 after = [ "network-online.target" ];
36 requires = [ "network-online.target" ];
39 format = pkgs.formats.toml { };
40 conf = format.generate "vector.toml" cfg.settings;
41 validateConfig = file:
42 pkgs.runCommand "validate-vector-conf" {
43 nativeBuildInputs = [ pkgs.vector ];
45 vector validate --no-environment "${file}"
46 ln -s "${file}" "$out"
50 ExecStart = "${lib.getExe cfg.package} --config ${validateConfig conf}";
53 StateDirectory = "vector";
54 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
55 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
56 # This group is required for accessing journald.
57 SupplementaryGroups = lib.mkIf cfg.journaldAccess "systemd-journal";
60 StartLimitIntervalSec = 10;