-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bc0af1
commit a77fc83
Showing
7 changed files
with
191 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
cfg = config.services.fluent-bit; | ||
|
||
yamlFormat = pkgs.formats.yaml { }; | ||
|
||
configurationFile = | ||
if (cfg.configurationFile == null) then | ||
(yamlFormat.generate "fluent-bit.yaml" cfg.configuration) | ||
else | ||
cfg.configurationFile; | ||
in | ||
{ | ||
options.services.fluent-bit = { | ||
enable = lib.mkEnableOption "Fluent Bit"; | ||
package = lib.mkPackageOption pkgs "fluent-bit" { }; | ||
configurationFile = lib.mkOption { | ||
type = lib.types.nullOr lib.types.path; | ||
default = null; | ||
description = '' | ||
Fluent Bit configuration. See | ||
<https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/yaml> | ||
for supported values. | ||
{option}`configurationFile` takes precedence over {option}`configuration`. | ||
Note: Restricted evaluation blocks access to paths outside the Nix store. | ||
This means detecting content changes for mutable paths (i.e. not input or content-addressed) can't be done. | ||
As a result, `nixos-rebuild` won't reload/restart the systemd unit when mutable path contents change. | ||
`systemctl restart fluent-bit.service` must be used instead. | ||
''; | ||
example = /etc/fluent-bit/fluent-bit.yaml; | ||
}; | ||
configuration = lib.mkOption { | ||
type = yamlFormat.type; | ||
default = { }; | ||
description = '' | ||
See {option}`configurationFile`. | ||
{option}`configurationFile` takes precedence over {option}`configuration`. | ||
''; | ||
example = { | ||
service = { | ||
grace = 30; | ||
}; | ||
pipeline = { | ||
inputs = [ | ||
{ | ||
name = "systemd"; | ||
systemd_filter = "_SYSTEMD_UNIT=fluent-bit.service"; | ||
} | ||
]; | ||
outputs = [ | ||
{ | ||
name = "file"; | ||
path = "/var/log/fluent-bit"; | ||
file = "fluent-bit.out"; | ||
} | ||
]; | ||
}; | ||
}; | ||
}; | ||
user = lib.mkOption { | ||
type = lib.types.str; | ||
default = "root"; | ||
description = '' | ||
The user that runs Fluent Bit. | ||
''; | ||
example = "fluent-bit"; | ||
}; | ||
# See https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/yaml/service-section. | ||
grace = lib.mkOption { | ||
type = lib.types.ints.positive; | ||
default = 5; | ||
description = '' | ||
The grace time in `seconds` as an integer value. The engine loop uses a grace timeout to define the wait time before exiting. | ||
The `service.grace` option in the Fluent Bit configuration should be ≤ this option. | ||
''; | ||
example = 30; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
# See https://github.com/fluent/fluent-bit/blob/v3.2.2/init/systemd.in. | ||
systemd.services.fluent-bit = { | ||
description = "Fluent Bit"; | ||
after = [ "network.target" ]; | ||
requires = [ "network.target" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
serviceConfig = { | ||
User = cfg.user; | ||
ExecStart = builtins.concatStringsSep " " [ | ||
"${cfg.package}/bin/fluent-bit" | ||
"--config ${configurationFile}" | ||
]; | ||
TimeoutStopSec = cfg.grace; | ||
Restart = "always"; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import ./make-test-python.nix ( | ||
{ lib, pkgs, ... }: | ||
{ | ||
name = "fluent-bit"; | ||
|
||
nodes.machine = | ||
{ config, pkgs, ... }: | ||
{ | ||
services.fluent-bit = { | ||
enable = true; | ||
configuration = { | ||
pipeline = { | ||
inputs = [ | ||
{ | ||
name = "systemd"; | ||
systemd_filter = "_SYSTEMD_UNIT=fluent-bit.service"; | ||
} | ||
]; | ||
outputs = [ | ||
{ | ||
name = "file"; | ||
path = "/var/log/fluent-bit"; | ||
file = "fluent-bit.out"; | ||
} | ||
]; | ||
}; | ||
}; | ||
}; | ||
|
||
systemd.services.fluent-bit.serviceConfig.LogsDirectory = "fluent-bit"; | ||
}; | ||
|
||
testScript = '' | ||
start_all() | ||
machine.wait_for_unit("fluent-bit.service") | ||
machine.wait_for_file("/var/log/fluent-bit/fluent-bit.out") | ||
''; | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters