2020-12-03 08:41:04 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let cfg = config.services.vector;
|
|
|
|
|
2021-04-05 15:23:46 +00:00
|
|
|
in
|
|
|
|
{
|
2020-12-03 08:41:04 +00:00
|
|
|
options.services.vector = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "Vector, a high-performance observability data pipeline";
|
2020-12-03 08:41:04 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "vector" { };
|
2023-05-24 13:37:59 +00:00
|
|
|
|
2020-12-03 08:41:04 +00:00
|
|
|
journaldAccess = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-12-03 08:41:04 +00:00
|
|
|
Enable Vector to access journald.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = (pkgs.formats.json { }).type;
|
|
|
|
default = { };
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-12-03 08:41:04 +00:00
|
|
|
Specify the configuration for Vector in Nix.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-04-29 16:46:19 +00:00
|
|
|
# for cli usage
|
|
|
|
environment.systemPackages = [ pkgs.vector ];
|
2020-12-03 08:41:04 +00:00
|
|
|
|
|
|
|
systemd.services.vector = {
|
|
|
|
description = "Vector event and log aggregator";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
requires = [ "network-online.target" ];
|
2021-04-05 15:23:46 +00:00
|
|
|
serviceConfig =
|
|
|
|
let
|
|
|
|
format = pkgs.formats.toml { };
|
|
|
|
conf = format.generate "vector.toml" cfg.settings;
|
|
|
|
validateConfig = file:
|
2022-09-11 15:47:08 +00:00
|
|
|
pkgs.runCommand "validate-vector-conf" {
|
2022-09-14 18:05:37 +00:00
|
|
|
nativeBuildInputs = [ pkgs.vector ];
|
2022-09-11 15:47:08 +00:00
|
|
|
} ''
|
|
|
|
vector validate --no-environment "${file}"
|
2021-04-05 15:23:46 +00:00
|
|
|
ln -s "${file}" "$out"
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
2023-05-24 13:37:59 +00:00
|
|
|
ExecStart = "${getExe cfg.package} --config ${validateConfig conf}";
|
2023-04-29 16:46:19 +00:00
|
|
|
DynamicUser = true;
|
2024-01-02 11:29:13 +00:00
|
|
|
Restart = "always";
|
2021-04-05 15:23:46 +00:00
|
|
|
StateDirectory = "vector";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
|
|
|
|
# This group is required for accessing journald.
|
|
|
|
SupplementaryGroups = mkIf cfg.journaldAccess "systemd-journal";
|
|
|
|
};
|
2024-01-02 11:29:13 +00:00
|
|
|
unitConfig = {
|
|
|
|
StartLimitIntervalSec = 10;
|
|
|
|
StartLimitBurst = 5;
|
|
|
|
};
|
2020-12-03 08:41:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|