| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  |   cfg = config.services.rabbitmq; | 
					
						
							| 
									
										
										
										
											2014-07-26 14:33:22 +03:00
										 |  |  |   config_file = pkgs.writeText "rabbitmq.config" cfg.config; | 
					
						
							|  |  |  |   config_file_wo_suffix = builtins.substring 0 ((builtins.stringLength config_file) - 7) config_file; | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  | in { | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  |   ###### interface | 
					
						
							|  |  |  |   options = { | 
					
						
							|  |  |  |     services.rabbitmq = { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       enable = mkOption { | 
					
						
							|  |  |  |         default = false; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Whether to enable the RabbitMQ server, an Advanced Message | 
					
						
							|  |  |  |           Queuing Protocol (AMQP) broker. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       listenAddress = mkOption { | 
					
						
							|  |  |  |         default = "127.0.0.1"; | 
					
						
							|  |  |  |         example = ""; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           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 | 
					
						
							|  |  |  |           <literal>guest</literal> with password | 
					
						
							|  |  |  |           <literal>guest</literal> by default, so you should delete | 
					
						
							|  |  |  |           this user if you intend to allow external access. | 
					
						
							|  |  |  |         '';
 | 
					
						
							| 
									
										
										
										
											2015-01-26 02:07:05 +01:00
										 |  |  |         type = types.str; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       port = mkOption { | 
					
						
							|  |  |  |         default = 5672; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Port on which RabbitMQ will listen for AMQP connections. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         type = types.int; | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |       dataDir = mkOption { | 
					
						
							|  |  |  |         type = types.path; | 
					
						
							|  |  |  |         default = "/var/lib/rabbitmq"; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Data directory for rabbitmq. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-26 14:33:22 +03:00
										 |  |  |       cookie = mkOption { | 
					
						
							|  |  |  |         default = ""; | 
					
						
							|  |  |  |         type = types.str; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           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. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       config = mkOption { | 
					
						
							|  |  |  |         default = ""; | 
					
						
							|  |  |  |         type = types.str; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Verbatim configuration file contents. | 
					
						
							|  |  |  |           See http://www.rabbitmq.com/configure.htm | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       plugins = mkOption { | 
					
						
							|  |  |  |         default = []; | 
					
						
							|  |  |  |         type = types.listOf types.str; | 
					
						
							|  |  |  |         description = "The names of plugins to enable"; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### implementation | 
					
						
							|  |  |  |   config = mkIf cfg.enable { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     environment.systemPackages = [ pkgs.rabbitmq_server ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-26 15:20:25 +02:00
										 |  |  |     users.extraUsers.rabbitmq = { | 
					
						
							|  |  |  |       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; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     users.extraGroups.rabbitmq.gid = config.ids.gids.rabbitmq; | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |     systemd.services.rabbitmq = { | 
					
						
							|  |  |  |       description = "RabbitMQ Server"; | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |       wantedBy = [ "multi-user.target" ]; | 
					
						
							| 
									
										
										
										
											2015-01-26 02:07:05 +01:00
										 |  |  |       after = [ "network.target" ]; | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-26 02:07:05 +01:00
										 |  |  |       path = [ pkgs.rabbitmq_server pkgs.procps ]; | 
					
						
							| 
									
										
										
										
											2014-09-13 02:16:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |       environment = { | 
					
						
							|  |  |  |         RABBITMQ_MNESIA_BASE = "${cfg.dataDir}/mnesia"; | 
					
						
							|  |  |  |         RABBITMQ_NODE_IP_ADDRESS = cfg.listenAddress; | 
					
						
							| 
									
										
										
										
											2015-01-26 02:07:05 +01:00
										 |  |  |         RABBITMQ_NODE_PORT = toString cfg.port; | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |         RABBITMQ_SERVER_START_ARGS = "-rabbit error_logger tty -rabbit sasl_error_logger false"; | 
					
						
							| 
									
										
										
										
											2015-01-26 02:07:05 +01:00
										 |  |  |         RABBITMQ_PID_FILE = "${cfg.dataDir}/pid"; | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |         SYS_PREFIX = ""; | 
					
						
							| 
									
										
										
										
											2014-07-26 14:33:22 +03:00
										 |  |  |         RABBITMQ_ENABLED_PLUGINS_FILE = pkgs.writeText "enabled_plugins" ''
 | 
					
						
							|  |  |  |           [ ${concatStringsSep "," cfg.plugins} ]. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       } //  optionalAttrs (cfg.config != "") { RABBITMQ_CONFIG_FILE = config_file_wo_suffix; }; | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |       serviceConfig = { | 
					
						
							|  |  |  |         ExecStart = "${pkgs.rabbitmq_server}/sbin/rabbitmq-server"; | 
					
						
							| 
									
										
										
										
											2015-01-26 02:07:05 +01:00
										 |  |  |         ExecStop = "${pkgs.rabbitmq_server}/sbin/rabbitmqctl stop"; | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |         User = "rabbitmq"; | 
					
						
							|  |  |  |         Group = "rabbitmq"; | 
					
						
							| 
									
										
										
										
											2015-01-26 02:07:05 +01:00
										 |  |  |         WorkingDirectory = cfg.dataDir; | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-26 02:07:05 +01:00
										 |  |  |       postStart = ''
 | 
					
						
							|  |  |  |         rabbitmqctl wait ${cfg.dataDir}/pid | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |       preStart = ''
 | 
					
						
							| 
									
										
										
										
											2014-07-26 14:33:22 +03:00
										 |  |  |         ${optionalString (cfg.cookie != "") ''
 | 
					
						
							|  |  |  |             echo -n ${cfg.cookie} > ${cfg.dataDir}/.erlang.cookie | 
					
						
							|  |  |  |             chmod 400 ${cfg.dataDir}/.erlang.cookie | 
					
						
							|  |  |  |         ''}
 | 
					
						
							| 
									
										
										
										
											2014-03-10 11:10:32 +01:00
										 |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-31 17:04:05 +00:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |