at v206 4.2 kB view raw
1{ config, lib, pkgs, ... }: 2 3with pkgs; 4with lib; 5 6let 7 8 cfg = config.services.activemq; 9 10 activemqBroker = stdenv.mkDerivation { 11 name = "activemq-broker"; 12 phases = [ "installPhase" ]; 13 buildInputs = [ jdk ]; 14 installPhase = '' 15 mkdir -p $out/lib 16 source ${activemq}/lib/classpath.env 17 export CLASSPATH 18 ln -s "${./ActiveMQBroker.java}" ActiveMQBroker.java 19 javac -d $out/lib ActiveMQBroker.java 20 ''; 21 }; 22 23in { 24 25 options = { 26 services.activemq = { 27 enable = mkOption { 28 type = types.bool; 29 default = false; 30 description = '' 31 Enable the Apache ActiveMQ message broker service. 32 ''; 33 }; 34 configurationDir = mkOption { 35 description = '' 36 The base directory for ActiveMQ's configuration. 37 By default, this directory is searched for a file named activemq.xml, 38 which should contain the configuration for the broker service. 39 ''; 40 }; 41 configurationURI = mkOption { 42 type = types.string; 43 default = "xbean:activemq.xml"; 44 description = '' 45 The URI that is passed along to the BrokerFactory to 46 set up the configuration of the ActiveMQ broker service. 47 You should not need to change this. For custom configuration, 48 set the <literal>configurationDir</literal> instead, and create 49 an activemq.xml configuration file in it. 50 ''; 51 }; 52 baseDir = mkOption { 53 type = types.string; 54 default = "/var/activemq"; 55 description = '' 56 The base directory where ActiveMQ stores its persistent data and logs. 57 This will be overridden if you set "activemq.base" and "activemq.data" 58 in the <literal>javaProperties</literal> option. You can also override 59 this in activemq.xml. 60 ''; 61 }; 62 javaProperties = mkOption { 63 type = types.attrs; 64 default = { }; 65 example = { 66 "java.net.preferIPv4Stack" = "true"; 67 }; 68 apply = attrs: { 69 "activemq.base" = "${cfg.baseDir}"; 70 "activemq.data" = "${cfg.baseDir}/data"; 71 "activemq.conf" = "${cfg.configurationDir}"; 72 "activemq.home" = "${activemq}"; 73 } // attrs; 74 description = '' 75 Specifies Java properties that are sent to the ActiveMQ 76 broker service with the "-D" option. You can set properties 77 here to change the behaviour and configuration of the broker. 78 All essential properties that are not set here are automatically 79 given reasonable defaults. 80 ''; 81 }; 82 extraJavaOptions = mkOption { 83 type = types.string; 84 default = ""; 85 example = "-Xmx2G -Xms2G -XX:MaxPermSize=512M"; 86 description = '' 87 Add extra options here that you want to be sent to the 88 Java runtime when the broker service is started. 89 ''; 90 }; 91 }; 92 }; 93 94 config = mkIf cfg.enable { 95 users.extraUsers.activemq = { 96 description = "ActiveMQ server user"; 97 group = "activemq"; 98 uid = config.ids.uids.activemq; 99 }; 100 101 users.extraGroups.activemq.gid = config.ids.gids.activemq; 102 103 systemd.services.activemq_init = { 104 wantedBy = [ "activemq.service" ]; 105 partOf = [ "activemq.service" ]; 106 before = [ "activemq.service" ]; 107 serviceConfig.Type = "oneshot"; 108 script = '' 109 mkdir -p "${cfg.javaProperties."activemq.data"}" 110 chown -R activemq "${cfg.javaProperties."activemq.data"}" 111 ''; 112 }; 113 114 systemd.services.activemq = { 115 wantedBy = [ "multi-user.target" ]; 116 after = [ "network.target" ]; 117 path = [ jre ]; 118 serviceConfig.User = "activemq"; 119 script = '' 120 source ${activemq}/lib/classpath.env 121 export CLASSPATH=${activemqBroker}/lib:${cfg.configurationDir}:$CLASSPATH 122 exec java \ 123 ${concatStringsSep " \\\n" (mapAttrsToList (name: value: "-D${name}=${value}") cfg.javaProperties)} \ 124 ${cfg.extraJavaOptions} ActiveMQBroker "${cfg.configurationURI}" 125 ''; 126 }; 127 128 services.activemq.configurationDir = mkDefault "${activemq}/conf"; 129 130 }; 131 132}