@ -4,14 +4,18 @@ with lib;
let
cfg = config . services . rabbitmq ;
config_file = pkgs . writeText " r a b b i t m q . c o n f i g " cfg . config ;
config_file_wo_suffix = builtins . substring 0 ( ( builtins . stringLength config_file ) - 7 ) config_file ;
inherit ( builtins ) concatStringsSep ;
config_file_content = lib . generators . toKeyValue { } cfg . configItems ;
config_file = pkgs . writeText " r a b b i t m q . c o n f " config_file_content ;
advanced_config_file = pkgs . writeText " a d v a n c e d . c o n f i g " cfg . config ;
in {
###### interface
options = {
services . rabbitmq = {
enable = mkOption {
default = false ;
description = ''
@ -20,6 +24,15 @@ in {
'' ;
} ;
package = mkOption {
default = pkgs . rabbitmq-server ;
type = types . package ;
defaultText = " p k g s . r a b b i t m q - s e r v e r " ;
description = ''
Which rabbitmq package to use .
'' ;
} ;
listenAddress = mkOption {
default = " 1 2 7 . 0 . 0 . 1 " ;
example = " " ;
@ -30,6 +43,10 @@ in {
<literal> guest < /literal > with password
<literal> guest < /literal > by default , so you should delete
this user if you intend to allow external access .
Together with ' port' setting it's mostly an alias for
configItems . " l i s t e n e r s . t c p . 1 " and it's left for backwards
compatibility with previous version of this module .
'' ;
type = types . str ;
} ;
@ -60,11 +77,29 @@ in {
'' ;
} ;
configItems = mkOption {
default = { } ;
type = types . attrsOf types . str ;
example = ''
{
" a u t h _ b a c k e n d s . 1 . a u t h n " = " r a b b i t _ a u t h _ b a c k e n d _ l d a p " ;
" a u t h _ b a c k e n d s . 1 . a u t h z " = " r a b b i t _ a u t h _ b a c k e n d _ i n t e r n a l " ;
}
'' ;
description = ''
New style config options .
See http://www.rabbitmq.com/configure.html
'' ;
} ;
config = mkOption {
default = " " ;
type = types . str ;
description = ''
Verbatim configuration file contents .
Verbatim advanced configuration file contents .
Prefered way is to use configItems .
See http://www.rabbitmq.com/configure.html
'' ;
} ;
@ -74,6 +109,12 @@ in {
type = types . listOf types . str ;
description = " T h e n a m e s o f p l u g i n s t o e n a b l e " ;
} ;
pluginDirs = mkOption {
default = [ ] ;
type = types . listOf types . path ;
description = " T h e l i s t o f d i r e c t o r i e s c o n t a i n i n g e x t e r n a l p l u g i n s " ;
} ;
} ;
} ;
@ -81,7 +122,10 @@ in {
###### implementation
config = mkIf cfg . enable {
environment . systemPackages = [ pkgs . rabbitmq_server ] ;
# This is needed so we will have 'rabbitmqctl' in our PATH
environment . systemPackages = [ cfg . package ] ;
services . epmd . enable = true ;
users . users . rabbitmq = {
description = " R a b b i t M Q s e r v e r u s e r " ;
@ -93,44 +137,54 @@ in {
users . groups . rabbitmq . gid = config . ids . gids . rabbitmq ;
services . rabbitmq . configItems = {
" l i s t e n e r s . t c p . 1 " = mkDefault " ${ cfg . listenAddress } : ${ toString cfg . port } " ;
} ;
systemd . services . rabbitmq = {
description = " R a b b i t M Q S e r v e r " ;
wantedBy = [ " m u l t i - u s e r . t a r g e t " ] ;
after = [ " n e t w o r k . t a r g e t " ] ;
after = [ " n e t w o r k . t a r g e t " " e p m d . s o c k e t " ] ;
wants = [ " n e t w o r k . t a r g e t " " e p m d . s o c k e t " ] ;
path = [ pkgs . rabbitmq_server pkgs . procps ] ;
path = [ cfg . package pkgs . procps ] ;
environment = {
RABBITMQ_MNESIA_BASE = " ${ cfg . dataDir } / m n e s i a " ;
RABBITMQ_NODE_IP_ADDRESS = cfg . listenAddress ;
RABBITMQ_NODE_PORT = toString cfg . port ;
RABBITMQ_LOGS = " - " ;
RABBITMQ_SASL_LOGS = " - " ;
RABBITMQ_PID_FILE = " ${ cfg . dataDir } / p i d " ;
SYS_PREFIX = " " ;
RABBITMQ_CONFIG_FILE = config_file ;
RABBITMQ_PLUGINS_DIR = concatStringsSep " : " cfg . pluginDirs ;
RABBITMQ_ENABLED_PLUGINS_FILE = pkgs . writeText " e n a b l e d _ p l u g i n s " ''
[ $ { concatStringsSep " , " cfg . plugins } ] .
'' ;
} // optionalAttrs ( cfg . config != " " ) { RABBITMQ_CONFIG_FILE = config_file_wo_suffix ; } ;
} // optionalAttrs ( cfg . config != " " ) { RABBITMQ_ADVANCED_ CONFIG_FILE = advanced_ config_file; } ;
serviceConfig = {
ExecStart = " ${ pkgs . rabbitmq_server } / s b i n / r a b b i t m q - s e r v e r " ;
ExecStop = " ${ pkgs . rabbitmq_server } / s b i n / r a b b i t m q c t l s t o p " ;
PermissionsStartOnly = true ; # preStart must be run as root
ExecStart = " ${ cfg . package } / s b i n / r a b b i t m q - s e r v e r " ;
ExecStop = " ${ cfg . package } / s b i n / r a b b i t m q c t l s h u t d o w n " ;
User = " r a b b i t m q " ;
Group = " r a b b i t m q " ;
WorkingDirectory = cfg . dataDir ;
Type = " n o t i f y " ;
NotifyAccess = " a l l " ;
UMask = " 0 0 2 7 " ;
LimitNOFILE = " 1 0 0 0 0 0 " ;
Restart = " o n - f a i l u r e " ;
RestartSec = " 1 0 " ;
TimeoutStartSec = " 3 6 0 0 " ;
} ;
postStart = ''
rabbitmqctl wait $ { cfg . dataDir } /pid
'' ;
preStart = ''
$ { optionalString ( cfg . cookie != " " ) ''
echo - n $ { cfg . cookie } > $ { cfg . dataDir } /.erlang.cookie
chown rabbitmq:rabbitmq $ { cfg . dataDir } /.erlang.cookie
chmod 600 $ { cfg . dataDir } /.erlang.cookie
'' }
mkdir - p /var/log/rabbitmq
chown rabbitmq:rabbitmq /var/log/rabbitmq
'' ;
} ;