-
-
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
f84cd48
commit 4f85137
Showing
7 changed files
with
200 additions
and
22 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,115 @@ | ||
{ | ||
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. | ||
graceLimit = lib.mkOption { | ||
type = lib.types.nullOr ( | ||
lib.types.oneOf [ | ||
lib.types.ints.positive | ||
lib.types.str | ||
] | ||
); | ||
default = null; | ||
description = '' | ||
The grace time limit. Sets the systemd unit's TimeoutStopSec. | ||
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}" | ||
]; | ||
Restart = "always"; | ||
} | ||
// (lib.optionalAttrs (cfg.graceLimit != null) { | ||
TimeoutStopSec = cfg.graceLimit; | ||
}); | ||
}; | ||
}; | ||
} |
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