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