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