2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-03-31 19:04:05 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2011-03-31 19:04:05 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.rabbitmq;
|
2018-09-24 15:31:16 +02:00
|
|
|
|
|
|
|
inherit (builtins) concatStringsSep;
|
|
|
|
|
2021-08-30 05:53:12 +02:00
|
|
|
config_file_content = lib.generators.toKeyValue { } cfg.configItems;
|
2018-09-24 15:31:16 +02:00
|
|
|
config_file = pkgs.writeText "rabbitmq.conf" config_file_content;
|
|
|
|
|
|
|
|
advanced_config_file = pkgs.writeText "advanced.config" cfg.config;
|
2011-03-31 19:04:05 +02:00
|
|
|
|
2021-08-30 05:53:12 +02:00
|
|
|
in
|
|
|
|
{
|
2011-03-31 19:04:05 +02:00
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.rabbitmq = {
|
|
|
|
enable = mkOption {
|
2020-04-20 20:05:26 +02:00
|
|
|
type = types.bool;
|
2011-03-31 19:04:05 +02:00
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2011-03-31 19:04:05 +02:00
|
|
|
Whether to enable the RabbitMQ server, an Advanced Message
|
|
|
|
Queuing Protocol (AMQP) broker.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-24 15:31:16 +02:00
|
|
|
package = mkOption {
|
|
|
|
default = pkgs.rabbitmq-server;
|
|
|
|
type = types.package;
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression "pkgs.rabbitmq-server";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-09-24 15:31:16 +02:00
|
|
|
Which rabbitmq package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-03-31 19:04:05 +02:00
|
|
|
listenAddress = mkOption {
|
|
|
|
default = "127.0.0.1";
|
|
|
|
example = "";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2011-03-31 19:04:05 +02:00
|
|
|
IP address on which RabbitMQ will listen for AMQP
|
|
|
|
connections. Set to the empty string to listen on all
|
|
|
|
interfaces. Note that RabbitMQ creates a user named
|
2022-07-28 23:19:15 +02:00
|
|
|
`guest` with password
|
|
|
|
`guest` by default, so you should delete
|
2011-03-31 19:04:05 +02:00
|
|
|
this user if you intend to allow external access.
|
2018-09-24 15:31:16 +02:00
|
|
|
|
|
|
|
Together with 'port' setting it's mostly an alias for
|
|
|
|
configItems."listeners.tcp.1" and it's left for backwards
|
|
|
|
compatibility with previous version of this module.
|
2011-03-31 19:04:05 +02:00
|
|
|
'';
|
2015-01-26 02:07:05 +01:00
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
default = 5672;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2015-01-26 02:07:05 +01:00
|
|
|
Port on which RabbitMQ will listen for AMQP connections.
|
|
|
|
'';
|
2021-06-18 17:26:27 +02:00
|
|
|
type = types.port;
|
2011-03-31 19:04:05 +02:00
|
|
|
};
|
|
|
|
|
2014-03-10 11:10:32 +01:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/rabbitmq";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2014-03-10 11:10:32 +01:00
|
|
|
Data directory for rabbitmq.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-07-26 13:33:22 +02:00
|
|
|
cookie = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2014-07-26 13:33:22 +02:00
|
|
|
Erlang cookie is a string of arbitrary length which must
|
|
|
|
be the same for several nodes to be allowed to communicate.
|
|
|
|
Leave empty to generate automatically.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-24 15:31:16 +02:00
|
|
|
configItems = mkOption {
|
2021-08-30 05:53:12 +02:00
|
|
|
default = { };
|
2018-09-24 15:31:16 +02:00
|
|
|
type = types.attrsOf types.str;
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression ''
|
2019-09-25 19:49:36 +02:00
|
|
|
{
|
|
|
|
"auth_backends.1.authn" = "rabbit_auth_backend_ldap";
|
|
|
|
"auth_backends.1.authz" = "rabbit_auth_backend_internal";
|
|
|
|
}
|
|
|
|
'';
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-09-25 18:04:37 +02:00
|
|
|
Configuration options in RabbitMQ's new config file format,
|
|
|
|
which is a simple key-value format that can not express nested
|
2022-07-28 23:19:15 +02:00
|
|
|
data structures. This is known as the `rabbitmq.conf` file,
|
2018-09-25 18:04:37 +02:00
|
|
|
although outside NixOS that filename may have Erlang syntax, particularly
|
|
|
|
prior to RabbitMQ 3.7.0.
|
|
|
|
|
|
|
|
If you do need to express nested data structures, you can use
|
2022-07-28 23:19:15 +02:00
|
|
|
`config` option. Configuration from `config`
|
2018-11-03 19:17:45 +01:00
|
|
|
will be merged into these options by RabbitMQ at runtime to
|
2018-09-25 18:04:37 +02:00
|
|
|
form the final configuration.
|
|
|
|
|
2020-01-22 11:26:22 +01:00
|
|
|
See https://www.rabbitmq.com/configure.html#config-items
|
|
|
|
For the distinct formats, see https://www.rabbitmq.com/configure.html#config-file-formats
|
2018-09-24 15:31:16 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-07-26 13:33:22 +02:00
|
|
|
config = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-09-25 18:04:37 +02:00
|
|
|
Verbatim advanced configuration file contents using the Erlang syntax.
|
2022-07-28 23:19:15 +02:00
|
|
|
This is also known as the `advanced.config` file or the old config format.
|
2018-09-25 18:04:37 +02:00
|
|
|
|
2022-07-28 23:19:15 +02:00
|
|
|
`configItems` is preferred whenever possible. However, nested
|
|
|
|
data structures can only be expressed properly using the `config` option.
|
2018-09-25 18:04:37 +02:00
|
|
|
|
2022-07-28 23:19:15 +02:00
|
|
|
The contents of this option will be merged into the `configItems`
|
2018-09-25 18:04:37 +02:00
|
|
|
by RabbitMQ at runtime to form the final configuration.
|
2018-09-24 15:31:16 +02:00
|
|
|
|
2020-01-22 11:26:22 +01:00
|
|
|
See the second table on https://www.rabbitmq.com/configure.html#config-items
|
|
|
|
For the distinct formats, see https://www.rabbitmq.com/configure.html#config-file-formats
|
2014-07-26 13:33:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
2021-08-30 05:53:12 +02:00
|
|
|
default = [ ];
|
2014-07-26 13:33:22 +02:00
|
|
|
type = types.listOf types.str;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "The names of plugins to enable";
|
2014-07-26 13:33:22 +02:00
|
|
|
};
|
2018-09-24 15:31:16 +02:00
|
|
|
|
|
|
|
pluginDirs = mkOption {
|
2021-08-30 05:53:12 +02:00
|
|
|
default = [ ];
|
2018-09-24 15:31:16 +02:00
|
|
|
type = types.listOf types.path;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "The list of directories containing external plugins";
|
2018-09-24 15:31:16 +02:00
|
|
|
};
|
2021-08-30 10:11:49 +02:00
|
|
|
|
2021-09-11 18:36:22 +02:00
|
|
|
managementPlugin = {
|
2022-08-28 21:18:44 +02:00
|
|
|
enable = mkEnableOption (lib.mdDoc "the management plugin");
|
2021-09-11 18:36:22 +02:00
|
|
|
port = mkOption {
|
|
|
|
default = 15672;
|
|
|
|
type = types.port;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2021-09-11 18:36:22 +02:00
|
|
|
On which port to run the management plugin
|
|
|
|
'';
|
2021-08-30 10:11:49 +02:00
|
|
|
};
|
|
|
|
};
|
2014-03-10 11:10:32 +01:00
|
|
|
};
|
2011-03-31 19:04:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2018-09-24 15:31:16 +02:00
|
|
|
# This is needed so we will have 'rabbitmqctl' in our PATH
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
services.epmd.enable = true;
|
2011-03-31 19:04:05 +02:00
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users.rabbitmq = {
|
2013-08-26 15:20:25 +02:00
|
|
|
description = "RabbitMQ server user";
|
2014-03-10 11:10:32 +01:00
|
|
|
home = "${cfg.dataDir}";
|
2015-01-26 02:07:05 +01:00
|
|
|
createHome = true;
|
2013-08-26 15:20:25 +02:00
|
|
|
group = "rabbitmq";
|
|
|
|
uid = config.ids.uids.rabbitmq;
|
|
|
|
};
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.groups.rabbitmq.gid = config.ids.gids.rabbitmq;
|
2011-03-31 19:04:05 +02:00
|
|
|
|
2018-09-24 15:31:16 +02:00
|
|
|
services.rabbitmq.configItems = {
|
|
|
|
"listeners.tcp.1" = mkDefault "${cfg.listenAddress}:${toString cfg.port}";
|
2021-08-30 10:11:49 +02:00
|
|
|
} // optionalAttrs cfg.managementPlugin.enable {
|
|
|
|
"management.tcp.port" = toString cfg.managementPlugin.port;
|
|
|
|
"management.tcp.ip" = cfg.listenAddress;
|
2018-09-24 15:31:16 +02:00
|
|
|
};
|
|
|
|
|
2021-08-30 10:11:49 +02:00
|
|
|
services.rabbitmq.plugins = optional cfg.managementPlugin.enable "rabbitmq_management";
|
|
|
|
|
2014-03-10 11:10:32 +01:00
|
|
|
systemd.services.rabbitmq = {
|
|
|
|
description = "RabbitMQ Server";
|
2011-03-31 19:04:05 +02:00
|
|
|
|
2014-03-10 11:10:32 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2018-09-24 15:31:16 +02:00
|
|
|
after = [ "network.target" "epmd.socket" ];
|
|
|
|
wants = [ "network.target" "epmd.socket" ];
|
2011-03-31 19:04:05 +02:00
|
|
|
|
2018-10-03 09:55:41 +02:00
|
|
|
path = [
|
|
|
|
cfg.package
|
|
|
|
pkgs.coreutils # mkdir/chown/chmod for preStart
|
|
|
|
];
|
2014-09-13 02:16:53 +02:00
|
|
|
|
2014-03-10 11:10:32 +01:00
|
|
|
environment = {
|
|
|
|
RABBITMQ_MNESIA_BASE = "${cfg.dataDir}/mnesia";
|
2017-09-23 23:54:49 +02:00
|
|
|
RABBITMQ_LOGS = "-";
|
2014-03-10 11:10:32 +01:00
|
|
|
SYS_PREFIX = "";
|
2018-09-24 15:31:16 +02:00
|
|
|
RABBITMQ_CONFIG_FILE = config_file;
|
|
|
|
RABBITMQ_PLUGINS_DIR = concatStringsSep ":" cfg.pluginDirs;
|
2014-07-26 13:33:22 +02:00
|
|
|
RABBITMQ_ENABLED_PLUGINS_FILE = pkgs.writeText "enabled_plugins" ''
|
|
|
|
[ ${concatStringsSep "," cfg.plugins} ].
|
|
|
|
'';
|
2021-08-30 05:53:12 +02:00
|
|
|
} // optionalAttrs (cfg.config != "") { RABBITMQ_ADVANCED_CONFIG_FILE = advanced_config_file; };
|
2011-03-31 19:04:05 +02:00
|
|
|
|
2014-03-10 11:10:32 +01:00
|
|
|
serviceConfig = {
|
2018-09-24 15:31:16 +02:00
|
|
|
ExecStart = "${cfg.package}/sbin/rabbitmq-server";
|
|
|
|
ExecStop = "${cfg.package}/sbin/rabbitmqctl shutdown";
|
2014-03-10 11:10:32 +01:00
|
|
|
User = "rabbitmq";
|
|
|
|
Group = "rabbitmq";
|
2019-02-24 14:47:33 +01:00
|
|
|
LogsDirectory = "rabbitmq";
|
2015-01-26 02:07:05 +01:00
|
|
|
WorkingDirectory = cfg.dataDir;
|
2018-09-24 15:31:16 +02:00
|
|
|
Type = "notify";
|
|
|
|
NotifyAccess = "all";
|
|
|
|
UMask = "0027";
|
|
|
|
LimitNOFILE = "100000";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10";
|
|
|
|
TimeoutStartSec = "3600";
|
2011-03-31 19:04:05 +02:00
|
|
|
};
|
|
|
|
|
2014-03-10 11:10:32 +01:00
|
|
|
preStart = ''
|
2014-07-26 13:33:22 +02:00
|
|
|
${optionalString (cfg.cookie != "") ''
|
|
|
|
echo -n ${cfg.cookie} > ${cfg.dataDir}/.erlang.cookie
|
2017-09-23 23:54:49 +02:00
|
|
|
chmod 600 ${cfg.dataDir}/.erlang.cookie
|
2014-07-26 13:33:22 +02:00
|
|
|
''}
|
2014-03-10 11:10:32 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-03-31 19:04:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|