1 { config, lib, utils, pkgs, ... }:
13 cfg = config.services.filebeat;
15 json = pkgs.formats.json {};
22 enable = mkEnableOption "filebeat";
24 package = mkPackageOption pkgs "filebeat" {
25 example = "filebeat7";
30 Inputs specify how Filebeat locates and processes input data.
32 This is like `services.filebeat.settings.filebeat.inputs`,
33 but structured as an attribute set. This has the benefit
34 that multiple NixOS modules can contribute settings to a
35 single filebeat input.
37 An input type can be specified multiple times by choosing a
38 different `<name>` for each, but setting
39 [](#opt-services.filebeat.inputs._name_.type)
42 See <https://www.elastic.co/guide/en/beats/filebeat/current/configuration-filebeat-options.html>.
45 type = types.attrsOf (types.submodule ({ name, ... }: {
46 freeformType = json.type;
54 Look for the value after `type:` on
55 the individual input pages linked from
56 <https://www.elastic.co/guide/en/beats/filebeat/current/configuration-filebeat-options.html>.
61 example = literalExpression ''
63 journald.id = "everything"; # Only for filebeat7
76 Filebeat modules provide a quick way to get started
77 processing common log formats. They contain default
78 configurations, Elasticsearch ingest pipeline definitions,
79 and Kibana dashboards to help you implement and deploy a log
82 This is like `services.filebeat.settings.filebeat.modules`,
83 but structured as an attribute set. This has the benefit
84 that multiple NixOS modules can contribute settings to a
85 single filebeat module.
87 A module can be specified multiple times by choosing a
88 different `<name>` for each, but setting
89 [](#opt-services.filebeat.modules._name_.module)
92 See <https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules.html>.
95 type = types.attrsOf (types.submodule ({ name, ... }: {
96 freeformType = json.type;
102 The name of the module.
104 Look for the value after `module:` on
105 the individual input pages linked from
106 <https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules.html>.
111 example = literalExpression ''
116 var.paths = [ "/path/to/log/nginx/access.log*" ];
120 var.paths = [ "/path/to/log/nginx/error.log*" ];
127 settings = mkOption {
128 type = types.submodule {
129 freeformType = json.type;
133 output.elasticsearch.hosts = mkOption {
134 type = with types; listOf str;
135 default = [ "127.0.0.1:9200" ];
136 example = [ "myEShost:9200" ];
138 The list of Elasticsearch nodes to connect to.
140 The events are distributed to these nodes in round
141 robin order. If one node becomes unreachable, the
142 event is automatically sent to another node. Each
143 Elasticsearch node can be defined as a URL or
144 IP:PORT. For example:
146 `https://es.found.io:9230` or
147 `192.24.3.2:9300`. If no port is
148 specified, `9200` is used.
154 type = types.listOf json.type;
158 Inputs specify how Filebeat locates and processes
159 input data. Use [](#opt-services.filebeat.inputs) instead.
161 See <https://www.elastic.co/guide/en/beats/filebeat/current/configuration-filebeat-options.html>.
165 type = types.listOf json.type;
169 Filebeat modules provide a quick way to get started
170 processing common log formats. They contain default
171 configurations, Elasticsearch ingest pipeline
172 definitions, and Kibana dashboards to help you
173 implement and deploy a log monitoring solution.
175 Use [](#opt-services.filebeat.modules) instead.
177 See <https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules.html>.
184 example = literalExpression ''
187 output.elasticsearch = {
188 hosts = [ "myEShost:9200" ];
189 username = "filebeat_internal";
190 password = { _secret = "/var/keys/elasticsearch_password"; };
192 logging.level = "info";
198 Configuration for filebeat. See
199 <https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-reference-yml.html>
200 for supported values.
202 Options containing secret data should be set to an attribute
203 set containing the attribute `_secret` - a
204 string pointing to a file containing the value the option
205 should be set to. See the example to get a better picture of
206 this: in the resulting
207 {file}`filebeat.yml` file, the
208 `output.elasticsearch.password`
209 key will be set to the contents of the
210 {file}`/var/keys/elasticsearch_password` file.
216 config = mkIf cfg.enable {
218 services.filebeat.settings.filebeat.inputs = attrValues cfg.inputs;
219 services.filebeat.settings.filebeat.modules = attrValues cfg.modules;
221 systemd.services.filebeat = {
222 description = "Filebeat log shipper";
223 wantedBy = [ "multi-user.target" ];
224 wants = [ "elasticsearch.service" ];
225 after = [ "elasticsearch.service" ];
227 ExecStartPre = pkgs.writeShellScript "filebeat-exec-pre" ''
232 ${utils.genJqSecretsReplacementSnippet
234 "/var/lib/filebeat/filebeat.yml"
238 ${cfg.package}/bin/filebeat -e \
239 -c "/var/lib/filebeat/filebeat.yml" \
240 --path.data "/var/lib/filebeat"
243 StateDirectory = "filebeat";