2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.crowd;
|
|
|
|
|
|
|
|
pkg = cfg.package.override {
|
|
|
|
home = cfg.home;
|
|
|
|
port = cfg.listenPort;
|
|
|
|
openidPassword = cfg.openidPassword;
|
|
|
|
} // (optionalAttrs cfg.proxy.enable {
|
|
|
|
proxyUrl = "${cfg.proxy.scheme}://${cfg.proxy.name}:${toString cfg.proxy.port}";
|
|
|
|
});
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
crowdPropertiesFile = pkgs.writeText "crowd.properties" ''
|
|
|
|
application.name crowd-openid-server
|
|
|
|
application.password @NIXOS_CROWD_OPENID_PW@
|
|
|
|
application.base.url http://localhost:${toString cfg.listenPort}/openidserver
|
|
|
|
application.login.url http://localhost:${toString cfg.listenPort}/openidserver
|
|
|
|
application.login.url.template http://localhost:${toString cfg.listenPort}/openidserver?returnToUrl=''${RETURN_TO_URL}
|
|
|
|
|
|
|
|
crowd.server.url http://localhost:${toString cfg.listenPort}/crowd/services/
|
|
|
|
|
|
|
|
session.isauthenticated session.isauthenticated
|
|
|
|
session.tokenkey session.tokenkey
|
|
|
|
session.validationinterval 0
|
|
|
|
session.lastvalidation session.lastvalidation
|
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.crowd = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Atlassian Crowd service");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "crowd";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User which runs Crowd.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "crowd";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Group which runs Crowd.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
home = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/crowd";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Home directory of the Crowd 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-11-21 17:40:18 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 8092;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Port to listen on.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
openidPassword = mkOption {
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
default = "WILL_NEVER_BE_SET";
|
|
|
|
description = lib.mdDoc "Application password for OpenID server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
openidPasswordFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = lib.mdDoc "Path to the file containing the application password for OpenID server.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
catalinaOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "-Xms1024m" "-Xmx2048m" ];
|
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 "reverse proxy support");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "crowd.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-11-21 17:40:18 +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
|
|
|
};
|
|
|
|
|
|
|
|
secure = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether the connections to the proxy should be considered secure.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "atlassian-crowd" { };
|
|
|
|
|
|
|
|
jrePackage = mkPackageOption pkgs "oraclejre8" {
|
|
|
|
extraDescription = ''
|
|
|
|
::: {.note }
|
|
|
|
Atlassian only supports 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.${cfg.group} = {};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.home}' - ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d /run/atlassian-crowd - - - - -"
|
|
|
|
|
|
|
|
"L+ /run/atlassian-crowd/database - - - - ${cfg.home}/database"
|
|
|
|
"L+ /run/atlassian-crowd/logs - - - - ${cfg.home}/logs"
|
|
|
|
"L+ /run/atlassian-crowd/work - - - - ${cfg.home}/work"
|
|
|
|
"L+ /run/atlassian-crowd/server.xml - - - - ${cfg.home}/server.xml"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.atlassian-crowd = {
|
|
|
|
description = "Atlassian Crowd";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "postgresql.service" ];
|
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
|
|
|
|
path = [ cfg.jrePackage ];
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
JAVA_HOME = "${cfg.jrePackage}";
|
|
|
|
CATALINA_OPTS = concatStringsSep " " cfg.catalinaOptions;
|
|
|
|
CATALINA_TMPDIR = "/tmp";
|
2022-08-12 12:06:08 +00:00
|
|
|
JAVA_OPTS = mkIf (cfg.openidPasswordFile != null) "-Dcrowd.properties=${cfg.home}/crowd.properties";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
rm -rf ${cfg.home}/work
|
|
|
|
mkdir -p ${cfg.home}/{logs,database,work}
|
|
|
|
|
|
|
|
sed -e 's,port="8095",port="${toString cfg.listenPort}" address="${cfg.listenAddress}",' \
|
|
|
|
'' + (lib.optionalString cfg.proxy.enable ''
|
|
|
|
-e 's,compression="on",compression="off" protocol="HTTP/1.1" proxyName="${cfg.proxy.name}" proxyPort="${toString cfg.proxy.port}" scheme="${cfg.proxy.scheme}" secure="${boolToString cfg.proxy.secure}",' \
|
|
|
|
'') + ''
|
|
|
|
${pkg}/apache-tomcat/conf/server.xml.dist > ${cfg.home}/server.xml
|
2022-08-12 12:06:08 +00:00
|
|
|
|
|
|
|
${optionalString (cfg.openidPasswordFile != null) ''
|
|
|
|
install -m660 ${crowdPropertiesFile} ${cfg.home}/crowd.properties
|
|
|
|
${pkgs.replace-secret}/bin/replace-secret \
|
|
|
|
'@NIXOS_CROWD_OPENID_PW@' \
|
|
|
|
${cfg.openidPasswordFile} \
|
|
|
|
${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}/start_crowd.sh -fg";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|