1 { config, lib, pkgs, ... }:
7 cfg = config.services.confluence;
9 pkg = cfg.package.override (optionalAttrs cfg.sso.enable {
10 enableSSO = cfg.sso.enable;
13 crowdProperties = pkgs.writeText "crowd.properties" ''
14 application.name ${cfg.sso.applicationName}
15 application.password ${if cfg.sso.applicationPassword != null then cfg.sso.applicationPassword else "@NIXOS_CONFLUENCE_CROWD_SSO_PWD@"}
16 application.login.url ${cfg.sso.crowd}/console/
18 crowd.server.url ${cfg.sso.crowd}/services/
19 crowd.base.url ${cfg.sso.crowd}/
21 session.isauthenticated session.isauthenticated
22 session.tokenkey session.tokenkey
23 session.validationinterval ${toString cfg.sso.validationInterval}
24 session.lastvalidation session.lastvalidation
31 services.confluence = {
32 enable = mkEnableOption "Atlassian Confluence service";
36 default = "confluence";
37 description = "User which runs confluence.";
42 default = "confluence";
43 description = "Group which runs confluence.";
48 default = "/var/lib/confluence";
49 description = "Home directory of the confluence instance.";
52 listenAddress = mkOption {
54 default = "127.0.0.1";
55 description = "Address to listen on.";
58 listenPort = mkOption {
61 description = "Port to listen on.";
64 catalinaOptions = mkOption {
65 type = types.listOf types.str;
67 example = [ "-Xms1024m" "-Xmx2048m" "-Dconfluence.disable.peopledirectory.all=true" ];
68 description = "Java options to pass to catalina/tomcat.";
72 enable = mkEnableOption "proxy support";
76 example = "confluence.example.com";
77 description = "Virtual hostname at the proxy";
84 description = "Port used at the proxy";
91 description = "Protocol used at the proxy.";
96 enable = mkEnableOption "SSO with Atlassian Crowd";
100 example = "http://localhost:8095/crowd";
101 description = "Crowd Base URL without trailing slash";
104 applicationName = mkOption {
107 description = "Exact name of this Confluence instance in Crowd";
110 applicationPassword = mkOption {
111 type = types.nullOr types.str;
113 description = "Application password of this Confluence instance in Crowd";
116 applicationPasswordFile = mkOption {
117 type = types.nullOr types.str;
119 description = "Path to the application password for Crowd of Confluence.";
122 validationInterval = mkOption {
127 Set to 0, if you want authentication checks to occur on each
128 request. Otherwise set to the number of minutes between request
129 to validate if the user is logged in or out of the Crowd SSO
130 server. Setting this value to 1 or higher will increase the
131 performance of Crowd's integration.
136 package = mkPackageOption pkgs "atlassian-confluence" { };
138 jrePackage = mkPackageOption pkgs "oraclejre8" {
139 extraDescription = ''
141 Atlassian only supports the Oracle JRE (JRASERVER-46152).
148 config = mkIf cfg.enable {
149 users.users.${cfg.user} = {
155 { assertion = cfg.sso.enable -> ((cfg.sso.applicationPassword == null) != (cfg.sso.applicationPasswordFile));
156 message = "Please set either applicationPassword or applicationPasswordFile";
160 warnings = mkIf (cfg.sso.enable && cfg.sso.applicationPassword != null) [
161 "Using `services.confluence.sso.applicationPassword` is deprecated! Use `applicationPasswordFile` instead!"
164 users.groups.${cfg.group} = {};
166 systemd.tmpfiles.rules = [
167 "d '${cfg.home}' - ${cfg.user} - - -"
168 "d /run/confluence - - - - -"
170 "L+ /run/confluence/home - - - - ${cfg.home}"
171 "L+ /run/confluence/logs - - - - ${cfg.home}/logs"
172 "L+ /run/confluence/temp - - - - ${cfg.home}/temp"
173 "L+ /run/confluence/work - - - - ${cfg.home}/work"
174 "L+ /run/confluence/server.xml - - - - ${cfg.home}/server.xml"
177 systemd.services.confluence = {
178 description = "Atlassian Confluence";
180 wantedBy = [ "multi-user.target" ];
181 requires = [ "postgresql.service" ];
182 after = [ "postgresql.service" ];
184 path = [ cfg.jrePackage pkgs.bash ];
187 CONF_USER = cfg.user;
188 JAVA_HOME = "${cfg.jrePackage}";
189 CATALINA_OPTS = concatStringsSep " " cfg.catalinaOptions;
190 JAVA_OPTS = mkIf cfg.sso.enable "-Dcrowd.properties=${cfg.home}/crowd.properties";
194 mkdir -p ${cfg.home}/{logs,work,temp,deploy}
196 sed -e 's,port="8090",port="${toString cfg.listenPort}" address="${cfg.listenAddress}",' \
197 '' + (lib.optionalString cfg.proxy.enable ''
198 -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}",' \
200 ${pkg}/conf/server.xml.dist > ${cfg.home}/server.xml
202 ${optionalString cfg.sso.enable ''
203 install -m660 ${crowdProperties} ${cfg.home}/crowd.properties
204 ${optionalString (cfg.sso.applicationPasswordFile != null) ''
205 ${pkgs.replace-secret}/bin/replace-secret \
206 '@NIXOS_CONFLUENCE_CROWD_SSO_PWD@' \
207 ${cfg.sso.applicationPasswordFile} \
208 ${cfg.home}/crowd.properties
217 Restart = "on-failure";
219 ExecStart = "${pkg}/bin/start-confluence.sh -fg";
220 ExecStop = "${pkg}/bin/stop-confluence.sh";