2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.graylog;
|
|
|
|
|
|
|
|
confFile = pkgs.writeText "graylog.conf" ''
|
|
|
|
is_master = ${boolToString cfg.isMaster}
|
|
|
|
node_id_file = ${cfg.nodeIdFile}
|
|
|
|
password_secret = ${cfg.passwordSecret}
|
|
|
|
root_username = ${cfg.rootUsername}
|
|
|
|
root_password_sha2 = ${cfg.rootPasswordSha2}
|
|
|
|
elasticsearch_hosts = ${concatStringsSep "," cfg.elasticsearchHosts}
|
|
|
|
message_journal_dir = ${cfg.messageJournalDir}
|
|
|
|
mongodb_uri = ${cfg.mongodbUri}
|
|
|
|
plugin_dir = /var/lib/graylog/plugins
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
glPlugins = pkgs.buildEnv {
|
|
|
|
name = "graylog-plugins";
|
|
|
|
paths = cfg.plugins;
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.graylog = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "Graylog";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.graylog;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.graylog";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Graylog package to use.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "graylog";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User account under which graylog runs";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
isMaster = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether this is the master instance of your Graylog cluster";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nodeIdFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/graylog/server/node-id";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Path of the file containing the graylog node-id";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passwordSecret = mkOption {
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
You MUST set a secret to secure/pepper the stored user passwords here. Use at least 64 characters.
|
|
|
|
Generate one by using for example: pwgen -N 1 -s 96
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
rootUsername = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "admin";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Name of the default administrator user";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
rootPasswordSha2 = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "e3c652f0ba0b4801205814f8b6bc49672c4c74e25b497770bb89b22cdeb4e952";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
You MUST specify a hash password for the root user (which you only need to initially set up the
|
|
|
|
system and in case you lose connectivity to your authentication backend)
|
|
|
|
This password cannot be changed using the API or via the web interface. If you need to change it,
|
|
|
|
modify it here.
|
|
|
|
Create one by using for example: echo -n yourpassword | shasum -a 256
|
|
|
|
and use the resulting hash value as string for the option
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
elasticsearchHosts = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''[ "http://node1:9200" "http://user:password@node2:19200" ]'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "List of valid URIs of the http ports of your elastic nodes. If one or more of your elasticsearch hosts require authentication, include the credentials in each node URI that requires authentication";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
messageJournalDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/graylog/data/journal";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The directory which will be used to store the message journal. The directory must be exclusively used by Graylog and must not contain any other files than the ones created by Graylog itself";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mongodbUri = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "mongodb://localhost/graylog";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "MongoDB connection string. See http://docs.mongodb.org/manual/reference/connection-string/ for details";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Any other configuration options you might want to add";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Extra graylog plugins";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = [ ];
|
|
|
|
type = types.listOf types.package;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.users = mkIf (cfg.user == "graylog") {
|
|
|
|
graylog = {
|
2021-09-18 10:52:07 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
group = "graylog";
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Graylog server daemon user";
|
|
|
|
};
|
|
|
|
};
|
2022-03-30 09:31:56 +00:00
|
|
|
users.groups = mkIf (cfg.user == "graylog") { graylog = {}; };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.messageJournalDir}' - ${cfg.user} - - -"
|
|
|
|
];
|
|
|
|
|
2021-03-20 04:20:00 +00:00
|
|
|
systemd.services.graylog = {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Graylog Server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment = {
|
|
|
|
GRAYLOG_CONF = "${confFile}";
|
|
|
|
};
|
2021-03-20 04:20:00 +00:00
|
|
|
path = [ pkgs.which pkgs.procps ];
|
2020-04-24 23:36:52 +00:00
|
|
|
preStart = ''
|
|
|
|
rm -rf /var/lib/graylog/plugins || true
|
|
|
|
mkdir -p /var/lib/graylog/plugins -m 755
|
|
|
|
|
|
|
|
mkdir -p "$(dirname ${cfg.nodeIdFile})"
|
|
|
|
chown -R ${cfg.user} "$(dirname ${cfg.nodeIdFile})"
|
|
|
|
|
|
|
|
for declarativeplugin in `ls ${glPlugins}/bin/`; do
|
|
|
|
ln -sf ${glPlugins}/bin/$declarativeplugin /var/lib/graylog/plugins/$declarativeplugin
|
|
|
|
done
|
|
|
|
for includedplugin in `ls ${cfg.package}/plugin/`; do
|
|
|
|
ln -s ${cfg.package}/plugin/$includedplugin /var/lib/graylog/plugins/$includedplugin || true
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
User="${cfg.user}";
|
|
|
|
StateDirectory = "graylog";
|
|
|
|
ExecStart = "${cfg.package}/bin/graylogctl run";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|