1 { config, lib, pkgs, ... }:
8 cfg = config.services.activemq;
10 activemqBroker = stdenv.mkDerivation {
11 name = "activemq-broker";
12 phases = [ "installPhase" ];
13 buildInputs = [ jdk ];
16 source ${activemq}/lib/classpath.env
18 ln -s "${./ActiveMQBroker.java}" ActiveMQBroker.java
19 javac -d $out/lib ActiveMQBroker.java
30 description = lib.mdDoc ''
31 Enable the Apache ActiveMQ message broker service.
34 configurationDir = mkOption {
35 default = "${activemq}/conf";
36 defaultText = literalExpression ''"''${pkgs.activemq}/conf"'';
38 description = lib.mdDoc ''
39 The base directory for ActiveMQ's configuration.
40 By default, this directory is searched for a file named activemq.xml,
41 which should contain the configuration for the broker service.
44 configurationURI = mkOption {
46 default = "xbean:activemq.xml";
47 description = lib.mdDoc ''
48 The URI that is passed along to the BrokerFactory to
49 set up the configuration of the ActiveMQ broker service.
50 You should not need to change this. For custom configuration,
51 set the `configurationDir` instead, and create
52 an activemq.xml configuration file in it.
57 default = "/var/activemq";
58 description = lib.mdDoc ''
59 The base directory where ActiveMQ stores its persistent data and logs.
60 This will be overridden if you set "activemq.base" and "activemq.data"
61 in the `javaProperties` option. You can also override
65 javaProperties = mkOption {
68 example = literalExpression ''
70 "java.net.preferIPv4Stack" = "true";
74 "activemq.base" = "${cfg.baseDir}";
75 "activemq.data" = "${cfg.baseDir}/data";
76 "activemq.conf" = "${cfg.configurationDir}";
77 "activemq.home" = "${activemq}";
79 description = lib.mdDoc ''
80 Specifies Java properties that are sent to the ActiveMQ
81 broker service with the "-D" option. You can set properties
82 here to change the behaviour and configuration of the broker.
83 All essential properties that are not set here are automatically
84 given reasonable defaults.
87 extraJavaOptions = mkOption {
88 type = types.separatedString " ";
90 example = "-Xmx2G -Xms2G -XX:MaxPermSize=512M";
91 description = lib.mdDoc ''
92 Add extra options here that you want to be sent to the
93 Java runtime when the broker service is started.
99 config = mkIf cfg.enable {
100 users.users.activemq = {
101 description = "ActiveMQ server user";
103 uid = config.ids.uids.activemq;
106 users.groups.activemq.gid = config.ids.gids.activemq;
108 systemd.services.activemq_init = {
109 wantedBy = [ "activemq.service" ];
110 partOf = [ "activemq.service" ];
111 before = [ "activemq.service" ];
112 serviceConfig.Type = "oneshot";
114 mkdir -p "${cfg.javaProperties."activemq.data"}"
115 chown -R activemq "${cfg.javaProperties."activemq.data"}"
119 systemd.services.activemq = {
120 wantedBy = [ "multi-user.target" ];
121 after = [ "network.target" ];
123 serviceConfig.User = "activemq";
125 source ${activemq}/lib/classpath.env
126 export CLASSPATH=${activemqBroker}/lib:${cfg.configurationDir}:$CLASSPATH
128 ${concatStringsSep " \\\n" (mapAttrsToList (name: value: "-D${name}=${value}") cfg.javaProperties)} \
129 ${cfg.extraJavaOptions} ActiveMQBroker "${cfg.configurationURI}"