at 21.11-pre 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 -Djava.endorsed.dirs=${cfg.package}/lib/endorsed 72 ''; 73 74 description = '' 75 Options for the JVM written to `nexus.jvmopts`. 76 Please refer to the docs (https://help.sonatype.com/repomanager3/installation/configuring-the-runtime-environment) 77 for further information. 78 ''; 79 }; 80 }; 81 }; 82 83 config = mkIf cfg.enable { 84 users.users.${cfg.user} = { 85 isSystemUser = true; 86 group = cfg.group; 87 home = cfg.home; 88 createHome = true; 89 }; 90 91 users.groups.${cfg.group} = {}; 92 93 systemd.services.nexus = { 94 description = "Sonatype Nexus3"; 95 96 wantedBy = [ "multi-user.target" ]; 97 98 path = [ cfg.home ]; 99 100 environment = { 101 NEXUS_USER = cfg.user; 102 NEXUS_HOME = cfg.home; 103 104 VM_OPTS_FILE = pkgs.writeText "nexus.vmoptions" cfg.jvmOpts; 105 }; 106 107 preStart = '' 108 mkdir -p ${cfg.home}/nexus3/etc 109 110 if [ ! -f ${cfg.home}/nexus3/etc/nexus.properties ]; then 111 echo "# Jetty section" > ${cfg.home}/nexus3/etc/nexus.properties 112 echo "application-port=${toString cfg.listenPort}" >> ${cfg.home}/nexus3/etc/nexus.properties 113 echo "application-host=${toString cfg.listenAddress}" >> ${cfg.home}/nexus3/etc/nexus.properties 114 else 115 sed 's/^application-port=.*/application-port=${toString cfg.listenPort}/' -i ${cfg.home}/nexus3/etc/nexus.properties 116 sed 's/^# application-port=.*/application-port=${toString cfg.listenPort}/' -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 sed 's/^# application-host=.*/application-host=${toString cfg.listenAddress}/' -i ${cfg.home}/nexus3/etc/nexus.properties 119 fi 120 ''; 121 122 script = "${cfg.package}/bin/nexus run"; 123 124 serviceConfig = { 125 User = cfg.user; 126 Group = cfg.group; 127 PrivateTmp = true; 128 LimitNOFILE = 102642; 129 }; 130 }; 131 }; 132 133 meta.maintainers = with lib.maintainers; [ ironpinguin ]; 134}