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