at 18.09-beta 3.9 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.nexus; 8 9in 10 11{ 12 options = { 13 services.nexus = { 14 enable = mkEnableOption "Sonatype Nexus3 OSS service"; 15 16 package = mkOption { 17 type = types.package; 18 default = pkgs.nexus; 19 description = "Package which runs Nexus3"; 20 }; 21 22 user = mkOption { 23 type = types.str; 24 default = "nexus"; 25 description = "User which runs Nexus3."; 26 }; 27 28 group = mkOption { 29 type = types.str; 30 default = "nexus"; 31 description = "Group which runs Nexus3."; 32 }; 33 34 home = mkOption { 35 type = types.str; 36 default = "/var/lib/sonatype-work"; 37 description = "Home directory of the Nexus3 instance."; 38 }; 39 40 listenAddress = mkOption { 41 type = types.str; 42 default = "127.0.0.1"; 43 description = "Address to listen on."; 44 }; 45 46 listenPort = mkOption { 47 type = types.int; 48 default = 8081; 49 description = "Port to listen on."; 50 }; 51 52 jvmOpts = mkOption { 53 type = types.lines; 54 default = '' 55 -Xms1200M 56 -Xmx1200M 57 -XX:MaxDirectMemorySize=2G 58 -XX:+UnlockDiagnosticVMOptions 59 -XX:+UnsyncloadClass 60 -XX:+LogVMOutput 61 -XX:LogFile=${cfg.home}/nexus3/log/jvm.log 62 -XX:-OmitStackTraceInFastThrow 63 -Djava.net.preferIPv4Stack=true 64 -Dkaraf.home=${cfg.package} 65 -Dkaraf.base=${cfg.package} 66 -Dkaraf.etc=${cfg.package}/etc/karaf 67 -Djava.util.logging.config.file=${cfg.package}/etc/karaf/java.util.logging.properties 68 -Dkaraf.data=${cfg.home}/nexus3 69 -Djava.io.tmpdir=${cfg.home}/nexus3/tmp 70 -Dkaraf.startLocalConsole=false 71 ''; 72 73 description = '' 74 Options for the JVM written to `nexus.jvmopts`. 75 Please refer to the docs (https://help.sonatype.com/repomanager3/installation/configuring-the-runtime-environment) 76 for further information. 77 ''; 78 }; 79 }; 80 }; 81 82 config = mkIf cfg.enable { 83 users.users."${cfg.user}" = { 84 isSystemUser = true; 85 group = cfg.group; 86 }; 87 88 users.groups."${cfg.group}" = {}; 89 90 systemd.services.nexus = { 91 description = "Sonatype Nexus3"; 92 93 wantedBy = [ "multi-user.target" ]; 94 95 path = [ cfg.home ]; 96 97 environment = { 98 NEXUS_USER = cfg.user; 99 NEXUS_HOME = cfg.home; 100 101 VM_OPTS_FILE = pkgs.writeText "nexus.vmoptions" cfg.jvmOpts; 102 }; 103 104 preStart = '' 105 mkdir -p ${cfg.home}/nexus3/etc 106 107 chown -R ${cfg.user}:${cfg.group} ${cfg.home} 108 109 if [ ! -f ${cfg.home}/nexus3/etc/nexus.properties ]; then 110 echo "# Jetty section" > ${cfg.home}/nexus3/etc/nexus.properties 111 echo "application-port=${toString cfg.listenPort}" >> ${cfg.home}/nexus3/etc/nexus.properties 112 echo "application-host=${toString cfg.listenAddress}" >> ${cfg.home}/nexus3/etc/nexus.properties 113 else 114 sed 's/^application-port=.*/application-port=${toString cfg.listenPort}/' -i ${cfg.home}/nexus3/etc/nexus.properties 115 sed 's/^# application-port=.*/application-port=${toString cfg.listenPort}/' -i ${cfg.home}/nexus3/etc/nexus.properties 116 sed 's/^application-host=.*/application-host=${toString cfg.listenAddress}/' -i ${cfg.home}/nexus3/etc/nexus.properties 117 sed 's/^# application-host=.*/application-host=${toString cfg.listenAddress}/' -i ${cfg.home}/nexus3/etc/nexus.properties 118 fi 119 ''; 120 121 script = "${cfg.package}/bin/nexus run"; 122 123 serviceConfig = { 124 User = cfg.user; 125 Group = cfg.group; 126 PrivateTmp = true; 127 PermissionsStartOnly = true; 128 LimitNOFILE = 102642; 129 }; 130 }; 131 }; 132 133 meta.maintainers = with lib.maintainers; [ ironpinguin ]; 134}