2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.confluence;
|
|
|
|
|
|
|
|
pkg = cfg.package.override (optionalAttrs cfg.sso.enable {
|
|
|
|
enableSSO = cfg.sso.enable;
|
|
|
|
});
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
crowdProperties = pkgs.writeText "crowd.properties" ''
|
|
|
|
application.name ${cfg.sso.applicationName}
|
|
|
|
application.password ${if cfg.sso.applicationPassword != null then cfg.sso.applicationPassword else "@NIXOS_CONFLUENCE_CROWD_SSO_PWD@"}
|
|
|
|
application.login.url ${cfg.sso.crowd}/console/
|
|
|
|
|
|
|
|
crowd.server.url ${cfg.sso.crowd}/services/
|
|
|
|
crowd.base.url ${cfg.sso.crowd}/
|
|
|
|
|
|
|
|
session.isauthenticated session.isauthenticated
|
|
|
|
session.tokenkey session.tokenkey
|
|
|
|
session.validationinterval ${toString cfg.sso.validationInterval}
|
|
|
|
session.lastvalidation session.lastvalidation
|
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.confluence = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Atlassian Confluence service");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "confluence";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User which runs confluence.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "confluence";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Group which runs confluence.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
home = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/confluence";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Home directory of the confluence instance.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Address to listen on.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
listenPort = mkOption {
|
2022-12-17 10:02:37 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 8090;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Port to listen on.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
catalinaOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "-Xms1024m" "-Xmx2048m" "-Dconfluence.disable.peopledirectory.all=true" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Java options to pass to catalina/tomcat.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
proxy = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "proxy support");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "confluence.example.com";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Virtual hostname at the proxy";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2022-12-17 10:02:37 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 443;
|
|
|
|
example = 80;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Port used at the proxy";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
scheme = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "https";
|
|
|
|
example = "http";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Protocol used at the proxy.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
sso = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "SSO with Atlassian Crowd");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
crowd = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "http://localhost:8095/crowd";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Crowd Base URL without trailing slash";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
applicationName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "jira";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Exact name of this Confluence instance in Crowd";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
applicationPassword = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = lib.mdDoc "Application password of this Confluence instance in Crowd";
|
|
|
|
};
|
|
|
|
|
|
|
|
applicationPasswordFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = lib.mdDoc "Path to the application password for Crowd of Confluence.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
validationInterval = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 2;
|
|
|
|
example = 0;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Set to 0, if you want authentication checks to occur on each
|
|
|
|
request. Otherwise set to the number of minutes between request
|
|
|
|
to validate if the user is logged in or out of the Crowd SSO
|
|
|
|
server. Setting this value to 1 or higher will increase the
|
|
|
|
performance of Crowd's integration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.atlassian-confluence;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.atlassian-confluence";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Atlassian Confluence package to use.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
jrePackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.oraclejre8;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.oraclejre8";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Note that Atlassian only support the Oracle JRE (JRASERVER-46152).";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
users.users.${cfg.user} = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = cfg.group;
|
|
|
|
};
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
assertions = [
|
|
|
|
{ assertion = cfg.sso.enable -> ((cfg.sso.applicationPassword == null) != (cfg.sso.applicationPasswordFile));
|
|
|
|
message = "Please set either applicationPassword or applicationPasswordFile";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
warnings = mkIf (cfg.sso.enable && cfg.sso.applicationPassword != null) [
|
|
|
|
"Using `services.confluence.sso.applicationPassword` is deprecated! Use `applicationPasswordFile` instead!"
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
users.groups.${cfg.group} = {};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.home}' - ${cfg.user} - - -"
|
|
|
|
"d /run/confluence - - - - -"
|
|
|
|
|
|
|
|
"L+ /run/confluence/home - - - - ${cfg.home}"
|
|
|
|
"L+ /run/confluence/logs - - - - ${cfg.home}/logs"
|
|
|
|
"L+ /run/confluence/temp - - - - ${cfg.home}/temp"
|
|
|
|
"L+ /run/confluence/work - - - - ${cfg.home}/work"
|
|
|
|
"L+ /run/confluence/server.xml - - - - ${cfg.home}/server.xml"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.confluence = {
|
|
|
|
description = "Atlassian Confluence";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "postgresql.service" ];
|
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
|
|
|
|
path = [ cfg.jrePackage pkgs.bash ];
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
CONF_USER = cfg.user;
|
|
|
|
JAVA_HOME = "${cfg.jrePackage}";
|
|
|
|
CATALINA_OPTS = concatStringsSep " " cfg.catalinaOptions;
|
2022-08-12 12:06:08 +00:00
|
|
|
JAVA_OPTS = mkIf cfg.sso.enable "-Dcrowd.properties=${cfg.home}/crowd.properties";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${cfg.home}/{logs,work,temp,deploy}
|
|
|
|
|
|
|
|
sed -e 's,port="8090",port="${toString cfg.listenPort}" address="${cfg.listenAddress}",' \
|
|
|
|
'' + (lib.optionalString cfg.proxy.enable ''
|
|
|
|
-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}",' \
|
|
|
|
'') + ''
|
|
|
|
${pkg}/conf/server.xml.dist > ${cfg.home}/server.xml
|
2022-08-12 12:06:08 +00:00
|
|
|
|
|
|
|
${optionalString cfg.sso.enable ''
|
|
|
|
install -m660 ${crowdProperties} ${cfg.home}/crowd.properties
|
|
|
|
${optionalString (cfg.sso.applicationPasswordFile != null) ''
|
|
|
|
${pkgs.replace-secret}/bin/replace-secret \
|
|
|
|
'@NIXOS_CONFLUENCE_CROWD_SSO_PWD@' \
|
|
|
|
${cfg.sso.applicationPasswordFile} \
|
|
|
|
${cfg.home}/crowd.properties
|
|
|
|
''}
|
|
|
|
''}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
PrivateTmp = true;
|
2022-05-18 14:49:53 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10";
|
2020-04-24 23:36:52 +00:00
|
|
|
ExecStart = "${pkg}/bin/start-confluence.sh -fg";
|
|
|
|
ExecStop = "${pkg}/bin/stop-confluence.sh";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|