1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.services.vector;
9
10in
11{
12 options.services.vector = {
13 enable = lib.mkEnableOption "Vector, a high-performance observability data pipeline";
14
15 package = lib.mkPackageOption pkgs "vector" { };
16
17 journaldAccess = lib.mkOption {
18 type = lib.types.bool;
19 default = false;
20 description = ''
21 Enable Vector to access journald.
22 '';
23 };
24
25 settings = lib.mkOption {
26 type = (pkgs.formats.json { }).type;
27 default = { };
28 description = ''
29 Specify the configuration for Vector in Nix.
30 '';
31 };
32 };
33
34 config = lib.mkIf cfg.enable {
35 # for cli usage
36 environment.systemPackages = [ cfg.package ];
37
38 systemd.services.vector = {
39 description = "Vector event and log aggregator";
40 wantedBy = [ "multi-user.target" ];
41 after = [ "network-online.target" ];
42 requires = [ "network-online.target" ];
43 serviceConfig =
44 let
45 format = pkgs.formats.toml { };
46 conf = format.generate "vector.toml" cfg.settings;
47 validateConfig =
48 file:
49 pkgs.runCommand "validate-vector-conf"
50 {
51 nativeBuildInputs = [ cfg.package ];
52 }
53 ''
54 vector validate --no-environment "${file}"
55 ln -s "${file}" "$out"
56 '';
57 in
58 {
59 ExecStart = "${lib.getExe cfg.package} --config ${validateConfig conf}";
60 DynamicUser = true;
61 Restart = "always";
62 StateDirectory = "vector";
63 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
64 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
65 # This group is required for accessing journald.
66 SupplementaryGroups = lib.mkIf cfg.journaldAccess "systemd-journal";
67 };
68 unitConfig = {
69 StartLimitIntervalSec = 10;
70 StartLimitBurst = 5;
71 };
72 };
73 };
74}