1 { config, lib, pkgs, ... }:
3 cfg = config.services.logstash;
4 ops = lib.optionalString;
5 verbosityFlag = "--log.level " + cfg.logLevel;
7 logstashConf = pkgs.writeText "logstash.conf" ''
21 logstashSettingsYml = pkgs.writeText "logstash.yml" cfg.extraSettings;
23 logstashJvmOptionsFile = pkgs.writeText "jvm.options" cfg.extraJvmOptions;
25 logstashSettingsDir = pkgs.runCommand "logstash-settings" {
26 inherit logstashJvmOptionsFile;
27 inherit logstashSettingsYml;
28 preferLocalBuild = true;
31 ln -s $logstashSettingsYml $out/logstash.yml
32 ln -s $logstashJvmOptionsFile $out/jvm.options
38 (lib.mkRenamedOptionModule [ "services" "logstash" "address" ] [ "services" "logstash" "listenAddress" ])
39 (lib.mkRemovedOptionModule [ "services" "logstash" "enableWeb" ] "The web interface was removed from logstash")
48 enable = lib.mkOption {
49 type = lib.types.bool;
51 description = "Enable logstash.";
54 package = lib.mkPackageOption pkgs "logstash" { };
56 plugins = lib.mkOption {
57 type = lib.types.listOf lib.types.path;
59 example = lib.literalExpression "[ pkgs.logstash-contrib ]";
60 description = "The paths to find other logstash plugins in.";
63 dataDir = lib.mkOption {
65 default = "/var/lib/logstash";
67 A path to directory writable by logstash that it uses to store data.
68 Plugins will also have access to this path.
72 logLevel = lib.mkOption {
73 type = lib.types.enum [ "debug" "info" "warn" "error" "fatal" ];
75 description = "Logging verbosity level.";
78 filterWorkers = lib.mkOption {
81 description = "The quantity of filter workers to run.";
84 listenAddress = lib.mkOption {
86 default = "127.0.0.1";
87 description = "Address on which to start webserver.";
93 description = "Port on which to start webserver.";
96 inputConfig = lib.mkOption {
97 type = lib.types.lines;
98 default = "generator { }";
99 description = "Logstash input configuration.";
100 example = lib.literalExpression ''
104 command => "''${config.systemd.package}/bin/journalctl -f -o json"
105 type => "syslog" codec => json {}
111 filterConfig = lib.mkOption {
112 type = lib.types.lines;
114 description = "logstash filter configuration.";
116 if [type] == "syslog" {
117 # Keep only relevant systemd fields
118 # https://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html
121 "type", "@timestamp", "@version",
122 "MESSAGE", "PRIORITY", "SYSLOG_FACILITY"
129 outputConfig = lib.mkOption {
130 type = lib.types.lines;
131 default = "stdout { codec => rubydebug }";
132 description = "Logstash output configuration.";
134 redis { host => ["localhost"] data_type => "list" key => "logstash" codec => json }
139 extraSettings = lib.mkOption {
140 type = lib.types.lines;
142 description = "Extra Logstash settings in YAML format.";
151 extraJvmOptions = lib.mkOption {
152 type = lib.types.lines;
154 description = "Extra JVM options, one per line (jvm.options format).";
165 ###### implementation
167 config = lib.mkIf cfg.enable {
168 systemd.services.logstash = {
169 description = "Logstash Daemon";
170 wantedBy = [ "multi-user.target" ];
171 path = [ pkgs.bash ];
173 ExecStartPre = ''${pkgs.coreutils}/bin/mkdir -p "${cfg.dataDir}" ; ${pkgs.coreutils}/bin/chmod 700 "${cfg.dataDir}"'';
174 ExecStart = lib.concatStringsSep " " (lib.filter (s: lib.stringLength s != 0) [
175 "${cfg.package}/bin/logstash"
176 "-w ${toString cfg.filterWorkers}"
177 (lib.concatMapStringsSep " " (x: "--path.plugins ${x}") cfg.plugins)
180 "--path.settings ${logstashSettingsDir}"
181 "--path.data ${cfg.dataDir}"