nixpkgs/nixos/modules/services/logging/vector.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
1.8 KiB
Nix
Raw Normal View History

2020-11-30 07:22:08 +00:00
{ config, lib, pkgs, ... }:
with lib;
let cfg = config.services.vector;
2021-04-04 23:30:12 +00:00
in
{
2020-11-30 07:22:08 +00:00
options.services.vector = {
enable = mkEnableOption (lib.mdDoc "Vector");
package = mkPackageOption pkgs "vector" { };
2023-05-10 13:58:50 +00:00
2020-11-30 07:22:08 +00:00
journaldAccess = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Enable Vector to access journald.
'';
};
settings = mkOption {
type = (pkgs.formats.json { }).type;
default = { };
description = lib.mdDoc ''
Specify the configuration for Vector in Nix.
'';
};
};
config = mkIf cfg.enable {
2023-04-23 23:53:51 +00:00
# for cli usage
environment.systemPackages = [ pkgs.vector ];
2020-11-30 07:22:08 +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-04 23:30:12 +00:00
serviceConfig =
let
format = pkgs.formats.toml { };
conf = format.generate "vector.toml" cfg.settings;
validateConfig = file:
pkgs.runCommand "validate-vector-conf" {
nativeBuildInputs = [ pkgs.vector ];
} ''
vector validate --no-environment "${file}"
2021-04-04 23:30:12 +00:00
ln -s "${file}" "$out"
'';
in
{
2023-05-10 13:58:50 +00:00
ExecStart = "${getExe cfg.package} --config ${validateConfig conf}";
2023-04-23 23:53:51 +00:00
DynamicUser = true;
Restart = "always";
2021-04-04 23:30:12 +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";
};
unitConfig = {
StartLimitIntervalSec = 10;
StartLimitBurst = 5;
};
2020-11-30 07:22:08 +00:00
};
};
}