nixpkgs/nixos/modules/services/web-apps/nexus.nix

134 lines
3.7 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.nexus;
in
{
options = {
services.nexus = {
enable = mkEnableOption "Sonatype Nexus3 OSS service";
package = mkOption {
type = types.package;
default = pkgs.nexus;
description = "Package which runs Nexus3";
};
user = mkOption {
type = types.str;
default = "nexus";
description = "User which runs Nexus3.";
};
group = mkOption {
type = types.str;
default = "nexus";
description = "Group which runs Nexus3.";
};
home = mkOption {
type = types.str;
default = "/var/lib/sonatype-work";
description = "Home directory of the Nexus3 instance.";
};
listenAddress = mkOption {
type = types.str;
default = "127.0.0.1";
description = "Address to listen on.";
};
listenPort = mkOption {
type = types.int;
default = 8081;
description = "Port to listen on.";
};
nexus: fix setup and nixos test (#40522) The original `nexus` derivation required `/run/sonatype-work/nexus3` which explicitly depended on the NixOS path structure. This would break `nexus` for everyone using `nixpkgs` on a non-NixOS system, additionally the module never created `/run/sonatype-work`, so the systemd unit created in `services.nexus` fails as well. The issue wasn't actively known as the `nixos/nexus` test wasn't registered in Hydra (see #40257). This patch contains the following changes: * Adds `tests.nexus` to `release.nix` to run the test on Hydra. * Makes JVM parameters configurable: by default all JVM options were located in `result/bin/nexus.vmoptions` which made it quite hard to patch these parameters. Now it's possible to override all parameters by running `VM_OPTS_FILE=custom-nexus.vmoptions ./result/bin/nexus run` (after patching the `nexus` shell script), additionally it's possible to override these parameters with `services.nexus.vmoptions`. * Bumped Nexus from 3.5.1 to 3.11.0 * Run the `nexus` test on Hydra with `callTest` in `nixos/release.nix`, furthermore the test checks if the UI is available on the specified port. * Added myself as maintainer for the NixOS test and the package to have some more people in case of further breakage. * Added sufficient disk space to the `nexus` test, otherwise the service fails with the following errors: ``` com.orientechnologies.orient.core.exception.ODatabaseException: Cannot create database 'accesslog' com.orientechnologies.orient.core.exception.OLowDiskSpaceException: Error occurred while executing a write operation to database 'accesslog' due to limited free space on the disk (242 MB). The database is now working in read-only mode. Please close the database (or stop OrientDB), make room on your hard drive and then reopen the database. The minimal required space is 256 MB. Required space is now set to 256MB (you can change it by setting parameter storage.diskCache.diskFreeSpaceLimit) . ``` /cc @ironpinguin @xeji
2018-05-15 12:10:29 +00:00
jvmOpts = mkOption {
type = types.lines;
default = ''
-Xms1200M
-Xmx1200M
-XX:MaxDirectMemorySize=2G
-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass
-XX:+LogVMOutput
-XX:LogFile=${cfg.home}/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=${cfg.package}
-Dkaraf.base=${cfg.package}
-Dkaraf.etc=${cfg.package}/etc/karaf
-Djava.util.logging.config.file=${cfg.package}/etc/karaf/java.util.logging.properties
nexus: fix setup and nixos test (#40522) The original `nexus` derivation required `/run/sonatype-work/nexus3` which explicitly depended on the NixOS path structure. This would break `nexus` for everyone using `nixpkgs` on a non-NixOS system, additionally the module never created `/run/sonatype-work`, so the systemd unit created in `services.nexus` fails as well. The issue wasn't actively known as the `nixos/nexus` test wasn't registered in Hydra (see #40257). This patch contains the following changes: * Adds `tests.nexus` to `release.nix` to run the test on Hydra. * Makes JVM parameters configurable: by default all JVM options were located in `result/bin/nexus.vmoptions` which made it quite hard to patch these parameters. Now it's possible to override all parameters by running `VM_OPTS_FILE=custom-nexus.vmoptions ./result/bin/nexus run` (after patching the `nexus` shell script), additionally it's possible to override these parameters with `services.nexus.vmoptions`. * Bumped Nexus from 3.5.1 to 3.11.0 * Run the `nexus` test on Hydra with `callTest` in `nixos/release.nix`, furthermore the test checks if the UI is available on the specified port. * Added myself as maintainer for the NixOS test and the package to have some more people in case of further breakage. * Added sufficient disk space to the `nexus` test, otherwise the service fails with the following errors: ``` com.orientechnologies.orient.core.exception.ODatabaseException: Cannot create database 'accesslog' com.orientechnologies.orient.core.exception.OLowDiskSpaceException: Error occurred while executing a write operation to database 'accesslog' due to limited free space on the disk (242 MB). The database is now working in read-only mode. Please close the database (or stop OrientDB), make room on your hard drive and then reopen the database. The minimal required space is 256 MB. Required space is now set to 256MB (you can change it by setting parameter storage.diskCache.diskFreeSpaceLimit) . ``` /cc @ironpinguin @xeji
2018-05-15 12:10:29 +00:00
-Dkaraf.data=${cfg.home}/nexus3
-Djava.io.tmpdir=${cfg.home}/nexus3/tmp
-Dkaraf.startLocalConsole=false
'';
description = ''
Options for the JVM written to `nexus.jvmopts`.
Please refer to the docs (https://help.sonatype.com/repomanager3/installation/configuring-the-runtime-environment)
for further information.
'';
};
};
};
config = mkIf cfg.enable {
2019-08-13 21:52:01 +00:00
users.users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
home = cfg.home;
createHome = true;
};
2019-08-13 21:52:01 +00:00
users.groups.${cfg.group} = {};
systemd.services.nexus = {
description = "Sonatype Nexus3";
wantedBy = [ "multi-user.target" ];
path = [ cfg.home ];
environment = {
NEXUS_USER = cfg.user;
NEXUS_HOME = cfg.home;
nexus: fix setup and nixos test (#40522) The original `nexus` derivation required `/run/sonatype-work/nexus3` which explicitly depended on the NixOS path structure. This would break `nexus` for everyone using `nixpkgs` on a non-NixOS system, additionally the module never created `/run/sonatype-work`, so the systemd unit created in `services.nexus` fails as well. The issue wasn't actively known as the `nixos/nexus` test wasn't registered in Hydra (see #40257). This patch contains the following changes: * Adds `tests.nexus` to `release.nix` to run the test on Hydra. * Makes JVM parameters configurable: by default all JVM options were located in `result/bin/nexus.vmoptions` which made it quite hard to patch these parameters. Now it's possible to override all parameters by running `VM_OPTS_FILE=custom-nexus.vmoptions ./result/bin/nexus run` (after patching the `nexus` shell script), additionally it's possible to override these parameters with `services.nexus.vmoptions`. * Bumped Nexus from 3.5.1 to 3.11.0 * Run the `nexus` test on Hydra with `callTest` in `nixos/release.nix`, furthermore the test checks if the UI is available on the specified port. * Added myself as maintainer for the NixOS test and the package to have some more people in case of further breakage. * Added sufficient disk space to the `nexus` test, otherwise the service fails with the following errors: ``` com.orientechnologies.orient.core.exception.ODatabaseException: Cannot create database 'accesslog' com.orientechnologies.orient.core.exception.OLowDiskSpaceException: Error occurred while executing a write operation to database 'accesslog' due to limited free space on the disk (242 MB). The database is now working in read-only mode. Please close the database (or stop OrientDB), make room on your hard drive and then reopen the database. The minimal required space is 256 MB. Required space is now set to 256MB (you can change it by setting parameter storage.diskCache.diskFreeSpaceLimit) . ``` /cc @ironpinguin @xeji
2018-05-15 12:10:29 +00:00
VM_OPTS_FILE = pkgs.writeText "nexus.vmoptions" cfg.jvmOpts;
};
preStart = ''
mkdir -p ${cfg.home}/nexus3/etc
if [ ! -f ${cfg.home}/nexus3/etc/nexus.properties ]; then
echo "# Jetty section" > ${cfg.home}/nexus3/etc/nexus.properties
echo "application-port=${toString cfg.listenPort}" >> ${cfg.home}/nexus3/etc/nexus.properties
echo "application-host=${toString cfg.listenAddress}" >> ${cfg.home}/nexus3/etc/nexus.properties
else
nexus: fix setup and nixos test (#40522) The original `nexus` derivation required `/run/sonatype-work/nexus3` which explicitly depended on the NixOS path structure. This would break `nexus` for everyone using `nixpkgs` on a non-NixOS system, additionally the module never created `/run/sonatype-work`, so the systemd unit created in `services.nexus` fails as well. The issue wasn't actively known as the `nixos/nexus` test wasn't registered in Hydra (see #40257). This patch contains the following changes: * Adds `tests.nexus` to `release.nix` to run the test on Hydra. * Makes JVM parameters configurable: by default all JVM options were located in `result/bin/nexus.vmoptions` which made it quite hard to patch these parameters. Now it's possible to override all parameters by running `VM_OPTS_FILE=custom-nexus.vmoptions ./result/bin/nexus run` (after patching the `nexus` shell script), additionally it's possible to override these parameters with `services.nexus.vmoptions`. * Bumped Nexus from 3.5.1 to 3.11.0 * Run the `nexus` test on Hydra with `callTest` in `nixos/release.nix`, furthermore the test checks if the UI is available on the specified port. * Added myself as maintainer for the NixOS test and the package to have some more people in case of further breakage. * Added sufficient disk space to the `nexus` test, otherwise the service fails with the following errors: ``` com.orientechnologies.orient.core.exception.ODatabaseException: Cannot create database 'accesslog' com.orientechnologies.orient.core.exception.OLowDiskSpaceException: Error occurred while executing a write operation to database 'accesslog' due to limited free space on the disk (242 MB). The database is now working in read-only mode. Please close the database (or stop OrientDB), make room on your hard drive and then reopen the database. The minimal required space is 256 MB. Required space is now set to 256MB (you can change it by setting parameter storage.diskCache.diskFreeSpaceLimit) . ``` /cc @ironpinguin @xeji
2018-05-15 12:10:29 +00:00
sed 's/^application-port=.*/application-port=${toString cfg.listenPort}/' -i ${cfg.home}/nexus3/etc/nexus.properties
sed 's/^# application-port=.*/application-port=${toString cfg.listenPort}/' -i ${cfg.home}/nexus3/etc/nexus.properties
sed 's/^application-host=.*/application-host=${toString cfg.listenAddress}/' -i ${cfg.home}/nexus3/etc/nexus.properties
sed 's/^# application-host=.*/application-host=${toString cfg.listenAddress}/' -i ${cfg.home}/nexus3/etc/nexus.properties
fi
'';
script = "${cfg.package}/bin/nexus run";
serviceConfig = {
User = cfg.user;
Group = cfg.group;
PrivateTmp = true;
LimitNOFILE = 102642;
};
};
};
2018-07-09 04:48:15 +00:00
meta.maintainers = with lib.maintainers; [ ironpinguin ];
}