summary refs log tree commit diff
path: root/nixos/modules/services/logging/fluentd.nix
blob: dd19617a13ffc680df5d53aeac86cec47b8c70ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.fluentd;

  pluginArgs = concatStringsSep " " (map (x: "-p ${x}") cfg.plugins);
in {
  ###### interface

  options = {

    services.fluentd = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable fluentd.";
      };

      config = mkOption {
        type = types.lines;
        default = "";
        description = "Fluentd config.";
      };

      package = mkOption {
        type = types.path;
        default = pkgs.fluentd;
        defaultText = literalExpression "pkgs.fluentd";
        description = "The fluentd package to use.";
      };

      plugins = mkOption {
        type = types.listOf types.path;
        default = [];
        description = ''
          A list of plugin paths to pass into fluentd. It will make plugins defined in ruby files
          there available in your config.
        '';
      };
    };
  };


  ###### implementation

  config = mkIf cfg.enable {
    systemd.services.fluentd = with pkgs; {
      description = "Fluentd Daemon";
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        ExecStart = "${cfg.package}/bin/fluentd -c ${pkgs.writeText "fluentd.conf" cfg.config} ${pluginArgs}";
        ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
      };
    };
  };
}