1 { config, lib, pkgs, ... }:
3 cfg = config.services.journalbeat;
5 journalbeatYml = pkgs.writeText "journalbeat.yml" ''
7 tags: ${builtins.toJSON cfg.tags}
16 services.journalbeat = {
18 enable = lib.mkEnableOption "journalbeat";
20 package = lib.mkPackageOption pkgs "journalbeat" { };
24 default = "journalbeat";
25 description = "Name of the beat";
29 type = lib.types.listOf lib.types.str;
31 description = "Tags to place on the shipped log messages";
34 stateDir = lib.mkOption {
36 default = "journalbeat";
38 Directory below `/var/lib/` to store journalbeat's
39 own logs and other data. This directory will be created automatically
40 using systemd's StateDirectory mechanism.
44 extraConfig = lib.mkOption {
45 type = lib.types.lines;
47 description = "Any other configuration options you want to add";
53 config = lib.mkIf cfg.enable {
57 assertion = !lib.hasPrefix "/" cfg.stateDir;
59 "The option services.journalbeat.stateDir shouldn't be an absolute directory." +
60 " It should be a directory relative to /var/lib/.";
64 systemd.services.journalbeat = {
65 description = "Journalbeat log shipper";
66 wantedBy = [ "multi-user.target" ];
67 wants = [ "elasticsearch.service" ];
68 after = [ "elasticsearch.service" ];
70 mkdir -p ${cfg.stateDir}/data
71 mkdir -p ${cfg.stateDir}/logs
74 StateDirectory = cfg.stateDir;
76 ${cfg.package}/bin/journalbeat \
77 -c ${journalbeatYml} \
78 -path.data /var/lib/${cfg.stateDir}/data \
79 -path.logs /var/lib/${cfg.stateDir}/logs'';