Files
nixpkgs/nixos/modules/services/logging/journalbeat.nix
Dark Steveneq 646b892680
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s
push sheeet
2025-10-09 14:15:47 +02:00

90 lines
2.1 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.journalbeat;
journalbeatYml = pkgs.writeText "journalbeat.yml" ''
name: ${cfg.name}
tags: ${builtins.toJSON cfg.tags}
${cfg.extraConfig}
'';
in
{
options = {
services.journalbeat = {
enable = lib.mkEnableOption "journalbeat";
package = lib.mkPackageOption pkgs "journalbeat" { };
name = lib.mkOption {
type = lib.types.str;
default = "journalbeat";
description = "Name of the beat";
};
tags = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Tags to place on the shipped log messages";
};
stateDir = lib.mkOption {
type = lib.types.str;
default = "journalbeat";
description = ''
Directory below `/var/lib/` to store journalbeat's
own logs and other data. This directory will be created automatically
using systemd's StateDirectory mechanism.
'';
};
extraConfig = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Any other configuration options you want to add";
};
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = !lib.hasPrefix "/" cfg.stateDir;
message =
"The option services.journalbeat.stateDir shouldn't be an absolute directory."
+ " It should be a directory relative to /var/lib/.";
}
];
systemd.services.journalbeat = {
description = "Journalbeat log shipper";
wantedBy = [ "multi-user.target" ];
wants = [ "elasticsearch.service" ];
after = [ "elasticsearch.service" ];
preStart = ''
mkdir -p ${cfg.stateDir}/data
mkdir -p ${cfg.stateDir}/logs
'';
serviceConfig = {
StateDirectory = cfg.stateDir;
ExecStart = ''
${cfg.package}/bin/journalbeat \
-c ${journalbeatYml} \
-path.data /var/lib/${cfg.stateDir}/data \
-path.logs /var/lib/${cfg.stateDir}/logs'';
Restart = "always";
};
};
};
}