aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/amqp/activemq/default.nix
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2019-10-05 12:43:18 +0000
committerKatharina Fey <kookie@spacekookie.de>2019-10-05 12:44:52 +0000
commitcf85056ba64caf3267d43255ef4a1243e9c8ee3b (patch)
tree3051519e9c8275b870aac43f80af875715c9d124 /nixpkgs/nixos/modules/services/amqp/activemq/default.nix
parent1148b1d122bc03e9a3665856c9b7bb96bd4e3994 (diff)
parent2436c27541b2f52deea3a4c1691216a02152e729 (diff)
Add 'nixpkgs/' from commit '2436c27541b2f52deea3a4c1691216a02152e729'
git-subtree-dir: nixpkgs git-subtree-mainline: 1148b1d122bc03e9a3665856c9b7bb96bd4e3994 git-subtree-split: 2436c27541b2f52deea3a4c1691216a02152e729
Diffstat (limited to 'nixpkgs/nixos/modules/services/amqp/activemq/default.nix')
-rw-r--r--nixpkgs/nixos/modules/services/amqp/activemq/default.nix131
1 files changed, 131 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/services/amqp/activemq/default.nix b/nixpkgs/nixos/modules/services/amqp/activemq/default.nix
new file mode 100644
index 00000000000..7729da27304
--- /dev/null
+++ b/nixpkgs/nixos/modules/services/amqp/activemq/default.nix
@@ -0,0 +1,131 @@
+{ config, lib, pkgs, ... }:
+
+with pkgs;
+with lib;
+
+let
+
+ cfg = config.services.activemq;
+
+ activemqBroker = stdenv.mkDerivation {
+ name = "activemq-broker";
+ phases = [ "installPhase" ];
+ buildInputs = [ jdk ];
+ installPhase = ''
+ mkdir -p $out/lib
+ source ${activemq}/lib/classpath.env
+ export CLASSPATH
+ ln -s "${./ActiveMQBroker.java}" ActiveMQBroker.java
+ javac -d $out/lib ActiveMQBroker.java
+ '';
+ };
+
+in {
+
+ options = {
+ services.activemq = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = ''
+ Enable the Apache ActiveMQ message broker service.
+ '';
+ };
+ configurationDir = mkOption {
+ default = "${activemq}/conf";
+ description = ''
+ The base directory for ActiveMQ's configuration.
+ By default, this directory is searched for a file named activemq.xml,
+ which should contain the configuration for the broker service.
+ '';
+ };
+ configurationURI = mkOption {
+ type = types.str;
+ default = "xbean:activemq.xml";
+ description = ''
+ The URI that is passed along to the BrokerFactory to
+ set up the configuration of the ActiveMQ broker service.
+ You should not need to change this. For custom configuration,
+ set the <literal>configurationDir</literal> instead, and create
+ an activemq.xml configuration file in it.
+ '';
+ };
+ baseDir = mkOption {
+ type = types.str;
+ default = "/var/activemq";
+ description = ''
+ The base directory where ActiveMQ stores its persistent data and logs.
+ This will be overridden if you set "activemq.base" and "activemq.data"
+ in the <literal>javaProperties</literal> option. You can also override
+ this in activemq.xml.
+ '';
+ };
+ javaProperties = mkOption {
+ type = types.attrs;
+ default = { };
+ example = {
+ "java.net.preferIPv4Stack" = "true";
+ };
+ apply = attrs: {
+ "activemq.base" = "${cfg.baseDir}";
+ "activemq.data" = "${cfg.baseDir}/data";
+ "activemq.conf" = "${cfg.configurationDir}";
+ "activemq.home" = "${activemq}";
+ } // attrs;
+ description = ''
+ Specifies Java properties that are sent to the ActiveMQ
+ broker service with the "-D" option. You can set properties
+ here to change the behaviour and configuration of the broker.
+ All essential properties that are not set here are automatically
+ given reasonable defaults.
+ '';
+ };
+ extraJavaOptions = mkOption {
+ type = types.separatedString " ";
+ default = "";
+ example = "-Xmx2G -Xms2G -XX:MaxPermSize=512M";
+ description = ''
+ Add extra options here that you want to be sent to the
+ Java runtime when the broker service is started.
+ '';
+ };
+ };
+ };
+
+ config = mkIf cfg.enable {
+ users.users.activemq = {
+ description = "ActiveMQ server user";
+ group = "activemq";
+ uid = config.ids.uids.activemq;
+ };
+
+ users.groups.activemq.gid = config.ids.gids.activemq;
+
+ systemd.services.activemq_init = {
+ wantedBy = [ "activemq.service" ];
+ partOf = [ "activemq.service" ];
+ before = [ "activemq.service" ];
+ serviceConfig.Type = "oneshot";
+ script = ''
+ mkdir -p "${cfg.javaProperties."activemq.data"}"
+ chown -R activemq "${cfg.javaProperties."activemq.data"}"
+ '';
+ };
+
+ systemd.services.activemq = {
+ wantedBy = [ "multi-user.target" ];
+ after = [ "network.target" ];
+ path = [ jre ];
+ serviceConfig.User = "activemq";
+ script = ''
+ source ${activemq}/lib/classpath.env
+ export CLASSPATH=${activemqBroker}/lib:${cfg.configurationDir}:$CLASSPATH
+ exec java \
+ ${concatStringsSep " \\\n" (mapAttrsToList (name: value: "-D${name}=${value}") cfg.javaProperties)} \
+ ${cfg.extraJavaOptions} ActiveMQBroker "${cfg.configurationURI}"
+ '';
+ };
+
+ };
+
+}