2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.rabbitmq;
|
|
|
|
|
|
|
|
inherit (builtins) concatStringsSep;
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
config_file_content = lib.generators.toKeyValue { } cfg.configItems;
|
2020-04-24 23:36:52 +00:00
|
|
|
config_file = pkgs.writeText "rabbitmq.conf" config_file_content;
|
|
|
|
|
|
|
|
advanced_config_file = pkgs.writeText "advanced.config" cfg.config;
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
in
|
|
|
|
{
|
2024-02-07 01:22:34 +00:00
|
|
|
|
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "rabbitmq" "cookie" ] ''
|
|
|
|
This option wrote the Erlang cookie to the store, while it should be kept secret.
|
|
|
|
Please remove it from your NixOS configuration and deploy a cookie securely instead.
|
|
|
|
The renamed `unsafeCookie` must ONLY be used in isolated non-production environments such as NixOS VM tests.
|
|
|
|
'')
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.rabbitmq = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable the RabbitMQ server, an Advanced Message
|
|
|
|
Queuing Protocol (AMQP) broker.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "rabbitmq-server" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
default = "127.0.0.1";
|
|
|
|
example = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00: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-08-12 12:06:08 +00:00
|
|
|
`guest` with password
|
|
|
|
`guest` by default, so you should delete
|
2020-04-24 23:36:52 +00:00
|
|
|
this user if you intend to allow external access.
|
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
default = 5672;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Port on which RabbitMQ will listen for AMQP connections.
|
|
|
|
'';
|
2021-07-14 22:03:04 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/rabbitmq";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Data directory for rabbitmq.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-02-07 01:22:34 +00:00
|
|
|
unsafeCookie = mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "";
|
|
|
|
type = types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00: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.
|
2024-02-07 01:22:34 +00:00
|
|
|
|
|
|
|
Setting the cookie via this option exposes the cookie to the store, which
|
|
|
|
is not recommended for security reasons.
|
|
|
|
Only use this option in an isolated non-production environment such as
|
|
|
|
NixOS VM tests.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configItems = mkOption {
|
2021-09-18 10:52:07 +00:00
|
|
|
default = { };
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.attrsOf types.str;
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
"auth_backends.1.authn" = "rabbit_auth_backend_ldap";
|
|
|
|
"auth_backends.1.authz" = "rabbit_auth_backend_internal";
|
|
|
|
}
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Configuration options in RabbitMQ's new config file format,
|
|
|
|
which is a simple key-value format that can not express nested
|
2022-08-12 12:06:08 +00:00
|
|
|
data structures. This is known as the `rabbitmq.conf` file,
|
2020-04-24 23:36:52 +00: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-08-12 12:06:08 +00:00
|
|
|
`config` option. Configuration from `config`
|
2020-04-24 23:36:52 +00:00
|
|
|
will be merged into these options by RabbitMQ at runtime to
|
|
|
|
form the final configuration.
|
|
|
|
|
|
|
|
See https://www.rabbitmq.com/configure.html#config-items
|
|
|
|
For the distinct formats, see https://www.rabbitmq.com/configure.html#config-file-formats
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Verbatim advanced configuration file contents using the Erlang syntax.
|
2022-08-12 12:06:08 +00:00
|
|
|
This is also known as the `advanced.config` file or the old config format.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
`configItems` is preferred whenever possible. However, nested
|
|
|
|
data structures can only be expressed properly using the `config` option.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
The contents of this option will be merged into the `configItems`
|
2020-04-24 23:36:52 +00:00
|
|
|
by RabbitMQ at runtime to form the final configuration.
|
|
|
|
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
2021-09-18 10:52:07 +00:00
|
|
|
default = [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.listOf types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "The names of plugins to enable";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pluginDirs = mkOption {
|
2021-09-18 10:52:07 +00:00
|
|
|
default = [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.listOf types.path;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "The list of directories containing external plugins";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-09-18 10:52:07 +00:00
|
|
|
|
|
|
|
managementPlugin = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "the management plugin";
|
2021-09-18 10:52:07 +00:00
|
|
|
port = mkOption {
|
|
|
|
default = 15672;
|
|
|
|
type = types.port;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-09-18 10:52:07 +00:00
|
|
|
On which port to run the management plugin
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
# This is needed so we will have 'rabbitmqctl' in our PATH
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
services.epmd.enable = true;
|
|
|
|
|
|
|
|
users.users.rabbitmq = {
|
|
|
|
description = "RabbitMQ server user";
|
|
|
|
home = "${cfg.dataDir}";
|
|
|
|
createHome = true;
|
|
|
|
group = "rabbitmq";
|
|
|
|
uid = config.ids.uids.rabbitmq;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.rabbitmq.gid = config.ids.gids.rabbitmq;
|
|
|
|
|
|
|
|
services.rabbitmq.configItems = {
|
|
|
|
"listeners.tcp.1" = mkDefault "${cfg.listenAddress}:${toString cfg.port}";
|
2021-09-18 10:52:07 +00:00
|
|
|
} // optionalAttrs cfg.managementPlugin.enable {
|
|
|
|
"management.tcp.port" = toString cfg.managementPlugin.port;
|
|
|
|
"management.tcp.ip" = cfg.listenAddress;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
services.rabbitmq.plugins = optional cfg.managementPlugin.enable "rabbitmq_management";
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.rabbitmq = {
|
|
|
|
description = "RabbitMQ Server";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" "epmd.socket" ];
|
|
|
|
wants = [ "network.target" "epmd.socket" ];
|
|
|
|
|
|
|
|
path = [
|
|
|
|
cfg.package
|
|
|
|
pkgs.coreutils # mkdir/chown/chmod for preStart
|
|
|
|
];
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
RABBITMQ_MNESIA_BASE = "${cfg.dataDir}/mnesia";
|
|
|
|
RABBITMQ_LOGS = "-";
|
|
|
|
SYS_PREFIX = "";
|
|
|
|
RABBITMQ_CONFIG_FILE = config_file;
|
|
|
|
RABBITMQ_PLUGINS_DIR = concatStringsSep ":" cfg.pluginDirs;
|
|
|
|
RABBITMQ_ENABLED_PLUGINS_FILE = pkgs.writeText "enabled_plugins" ''
|
|
|
|
[ ${concatStringsSep "," cfg.plugins} ].
|
|
|
|
'';
|
2021-09-18 10:52:07 +00:00
|
|
|
} // optionalAttrs (cfg.config != "") { RABBITMQ_ADVANCED_CONFIG_FILE = advanced_config_file; };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${cfg.package}/sbin/rabbitmq-server";
|
|
|
|
ExecStop = "${cfg.package}/sbin/rabbitmqctl shutdown";
|
|
|
|
User = "rabbitmq";
|
|
|
|
Group = "rabbitmq";
|
|
|
|
LogsDirectory = "rabbitmq";
|
|
|
|
WorkingDirectory = cfg.dataDir;
|
|
|
|
Type = "notify";
|
|
|
|
NotifyAccess = "all";
|
|
|
|
UMask = "0027";
|
|
|
|
LimitNOFILE = "100000";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10";
|
|
|
|
TimeoutStartSec = "3600";
|
|
|
|
};
|
|
|
|
|
|
|
|
preStart = ''
|
2024-02-07 01:22:34 +00:00
|
|
|
${optionalString (cfg.unsafeCookie != "") ''
|
|
|
|
install -m 600 <(echo -n ${cfg.unsafeCookie}) ${cfg.dataDir}/.erlang.cookie
|
2020-04-24 23:36:52 +00:00
|
|
|
''}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|