60 lines
2.2 KiB
Nix

{pkgs, lib, config, ...}:
with lib;
{
options.services.vector = {
enable = mkEnableOption "Enable the vector agent";
settings = mkOption {
description = "Settings for the vector agent";
default = {
data_dir = "/var/lib/vector";
};
defaultText = "{}";
};
stdoutPath = mkOption {
default = "/var/log/vector.out.log";
};
stderrPath = mkOption {
default = "/var/log/vector.err.log";
};
pidPath = mkOption {
default = "/var/log/vector.pid";
};
};
config = {
environment.etc."vector.yaml" = mkIf config.services.vector.enable {
text = (generators.toYAML {} config.services.vector.settings);
};
launchd.daemons.vector = mkIf config.services.vector.enable {
serviceConfig = {
ProgramArguments = [
"${pkgs.clio}/bin/clio"
"--out-path=${config.services.vector.stdoutPath}"
"--err-path=${config.services.vector.stdoutPath}"
"--pid-file=${config.services.vector.pidPath}"
"--paranoid"
"--"
"${pkgs.vector}/bin/vector"
"--verbose"
"--watch-config"
"--config=/etc/${config.environment.etc."vector.yaml".target}"
];
WatchPaths= [
"/etc/${config.environment.etc."vector.yaml".target}"
];
KeepAlive = true;
RunAtLoad = true;
};
};
environment.etc."newsyslog.d/org.nixos.vector.conf" = mkIf config.services.vector.enable {
text = ''
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
${config.services.vector.stdoutPath} zaphar:staff 644 10 1000 * BJ ${config.services.vector.pidPath} 1
${config.services.vector.stderrPath} zaphar:staff 644 10 1000 * BJ ${config.services.vector.pidPath} 1
'';
};
};
}