1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.confluence;
8
9 pkg = cfg.package.override (optionalAttrs cfg.sso.enable {
10 enableSSO = cfg.sso.enable;
11 crowdProperties = ''
12 application.name ${cfg.sso.applicationName}
13 application.password ${cfg.sso.applicationPassword}
14 application.login.url ${cfg.sso.crowd}/console/
15
16 crowd.server.url ${cfg.sso.crowd}/services/
17 crowd.base.url ${cfg.sso.crowd}/
18
19 session.isauthenticated session.isauthenticated
20 session.tokenkey session.tokenkey
21 session.validationinterval ${toString cfg.sso.validationInterval}
22 session.lastvalidation session.lastvalidation
23 '';
24 });
25
26in
27
28{
29 options = {
30 services.confluence = {
31 enable = mkEnableOption "Atlassian Confluence service";
32
33 user = mkOption {
34 type = types.str;
35 default = "confluence";
36 description = "User which runs confluence.";
37 };
38
39 group = mkOption {
40 type = types.str;
41 default = "confluence";
42 description = "Group which runs confluence.";
43 };
44
45 home = mkOption {
46 type = types.str;
47 default = "/var/lib/confluence";
48 description = "Home directory of the confluence instance.";
49 };
50
51 listenAddress = mkOption {
52 type = types.str;
53 default = "127.0.0.1";
54 description = "Address to listen on.";
55 };
56
57 listenPort = mkOption {
58 type = types.int;
59 default = 8090;
60 description = "Port to listen on.";
61 };
62
63 catalinaOptions = mkOption {
64 type = types.listOf types.str;
65 default = [];
66 example = [ "-Xms1024m" "-Xmx2048m" "-Dconfluence.disable.peopledirectory.all=true" ];
67 description = "Java options to pass to catalina/tomcat.";
68 };
69
70 proxy = {
71 enable = mkEnableOption "proxy support";
72
73 name = mkOption {
74 type = types.str;
75 example = "confluence.example.com";
76 description = "Virtual hostname at the proxy";
77 };
78
79 port = mkOption {
80 type = types.int;
81 default = 443;
82 example = 80;
83 description = "Port used at the proxy";
84 };
85
86 scheme = mkOption {
87 type = types.str;
88 default = "https";
89 example = "http";
90 description = "Protocol used at the proxy.";
91 };
92 };
93
94 sso = {
95 enable = mkEnableOption "SSO with Atlassian Crowd";
96
97 crowd = mkOption {
98 type = types.str;
99 example = "http://localhost:8095/crowd";
100 description = "Crowd Base URL without trailing slash";
101 };
102
103 applicationName = mkOption {
104 type = types.str;
105 example = "jira";
106 description = "Exact name of this Confluence instance in Crowd";
107 };
108
109 applicationPassword = mkOption {
110 type = types.str;
111 description = "Application password of this Confluence instance in Crowd";
112 };
113
114 validationInterval = mkOption {
115 type = types.int;
116 default = 2;
117 example = 0;
118 description = ''
119 Set to 0, if you want authentication checks to occur on each
120 request. Otherwise set to the number of minutes between request
121 to validate if the user is logged in or out of the Crowd SSO
122 server. Setting this value to 1 or higher will increase the
123 performance of Crowd's integration.
124 '';
125 };
126 };
127
128 package = mkOption {
129 type = types.package;
130 default = pkgs.atlassian-confluence;
131 defaultText = "pkgs.atlassian-confluence";
132 description = "Atlassian Confluence package to use.";
133 };
134
135 jrePackage = mkOption {
136 type = types.package;
137 default = pkgs.oraclejre8;
138 defaultText = "pkgs.oraclejre8";
139 description = "Note that Atlassian only support the Oracle JRE (JRASERVER-46152).";
140 };
141 };
142 };
143
144 config = mkIf cfg.enable {
145 users.users.${cfg.user} = {
146 isSystemUser = true;
147 group = cfg.group;
148 };
149
150 users.groups.${cfg.group} = {};
151
152 systemd.tmpfiles.rules = [
153 "d '${cfg.home}' - ${cfg.user} - - -"
154 "d /run/confluence - - - - -"
155
156 "L+ /run/confluence/home - - - - ${cfg.home}"
157 "L+ /run/confluence/logs - - - - ${cfg.home}/logs"
158 "L+ /run/confluence/temp - - - - ${cfg.home}/temp"
159 "L+ /run/confluence/work - - - - ${cfg.home}/work"
160 "L+ /run/confluence/server.xml - - - - ${cfg.home}/server.xml"
161 ];
162
163 systemd.services.confluence = {
164 description = "Atlassian Confluence";
165
166 wantedBy = [ "multi-user.target" ];
167 requires = [ "postgresql.service" ];
168 after = [ "postgresql.service" ];
169
170 path = [ cfg.jrePackage pkgs.bash ];
171
172 environment = {
173 CONF_USER = cfg.user;
174 JAVA_HOME = "${cfg.jrePackage}";
175 CATALINA_OPTS = concatStringsSep " " cfg.catalinaOptions;
176 };
177
178 preStart = ''
179 mkdir -p ${cfg.home}/{logs,work,temp,deploy}
180
181 sed -e 's,port="8090",port="${toString cfg.listenPort}" address="${cfg.listenAddress}",' \
182 '' + (lib.optionalString cfg.proxy.enable ''
183 -e 's,protocol="org.apache.coyote.http11.Http11NioProtocol",protocol="org.apache.coyote.http11.Http11NioProtocol" proxyName="${cfg.proxy.name}" proxyPort="${toString cfg.proxy.port}" scheme="${cfg.proxy.scheme}",' \
184 '') + ''
185 ${pkg}/conf/server.xml.dist > ${cfg.home}/server.xml
186 '';
187
188 serviceConfig = {
189 User = cfg.user;
190 Group = cfg.group;
191 PrivateTmp = true;
192 ExecStart = "${pkg}/bin/start-confluence.sh -fg";
193 ExecStop = "${pkg}/bin/stop-confluence.sh";
194 };
195 };
196 };
197}