···
{ config, lib, pkgs, ... }:
cfg = config.services.tomcat;
···
+
maintainers = with lib.maintainers; [ danbst ];
+
enable = lib.mkEnableOption (lib.mdDoc "Apache Tomcat");
+
package = lib.mkPackageOptionMD pkgs "tomcat9" { };
+
purifyOnStart = lib.mkOption {
description = lib.mdDoc ''
On startup, the `baseDir` directory is populated with various files,
···
+
baseDir = lib.mkOption {
description = lib.mdDoc ''
···
+
logDirs = lib.mkOption {
+
type = lib.types.listOf lib.types.path;
description = lib.mdDoc "Directories to create in baseDir/logs/";
+
extraConfigFiles = lib.mkOption {
+
type = lib.types.listOf lib.types.path;
description = lib.mdDoc "Extra configuration files to pull into the tomcat conf directory";
+
extraEnvironment = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
example = [ "ENVIRONMENT=production" ];
description = lib.mdDoc "Environment Variables to pass to the tomcat service";
+
extraGroups = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
description = lib.mdDoc "Defines extra groups to which the tomcat user belongs.";
description = lib.mdDoc "User account under which Apache Tomcat runs.";
description = lib.mdDoc "Group account under which Apache Tomcat runs.";
+
javaOpts = lib.mkOption {
+
type = lib.types.either (lib.types.listOf lib.types.str) lib.types.str;
description = lib.mdDoc "Parameters to pass to the Java Virtual Machine which spawns Apache Tomcat";
+
catalinaOpts = lib.mkOption {
+
type = lib.types.either (lib.types.listOf lib.types.str) lib.types.str;
description = lib.mdDoc "Parameters to pass to the Java Virtual Machine which spawns the Catalina servlet container";
+
sharedLibs = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
description = lib.mdDoc "List containing JAR files or directories with JAR files which are libraries shared by the web applications";
+
serverXml = lib.mkOption {
+
type = lib.types.lines;
description = lib.mdDoc ''
Verbatim server.xml configuration.
···
+
commonLibs = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
description = lib.mdDoc "List containing JAR files or directories with JAR files which are libraries shared by the web applications and the servlet container";
+
webapps = lib.mkOption {
+
type = lib.types.listOf lib.types.path;
default = [ tomcat.webapps ];
+
defaultText = lib.literalExpression "[ config.services.tomcat.package.webapps ]";
description = lib.mdDoc "List containing WAR files or directories with WAR files which are web applications to be deployed on Tomcat";
+
virtualHosts = lib.mkOption {
+
type = lib.types.listOf (lib.types.submodule {
description = lib.mdDoc "name of the virtualhost";
+
aliases = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
description = lib.mdDoc "aliases of the virtualhost";
+
webapps = lib.mkOption {
+
type = lib.types.listOf lib.types.path;
description = lib.mdDoc ''
List containing web application WAR files and/or directories containing
web applications and configuration files for the virtual host.
description = lib.mdDoc "List consisting of a virtual host name and a list of web applications to deploy on each virtual host";
+
logPerVirtualHost = lib.mkOption {
description = lib.mdDoc "Whether to enable logging per virtual host.";
+
jdk = lib.mkPackageOptionMD pkgs "jdk" { };
+
enable = lib.mkEnableOption "Apache Axis2 container";
+
services = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
description = lib.mdDoc "List containing AAR files or directories with AAR files which are web services to be deployed on Axis2";
+
config = lib.mkIf config.services.tomcat.enable {
users.groups.tomcat.gid = config.ids.gids.tomcat;
+
uid = config.ids.uids.tomcat;
description = "Tomcat user";
home = "/homeless-shelter";
···
ln -sfn ${tomcat}/conf/$i ${cfg.baseDir}/conf/`basename $i`
+
${lib.optionalString (cfg.extraConfigFiles != []) ''
for i in ${toString cfg.extraConfigFiles}; do
ln -sfn $i ${cfg.baseDir}/conf/`basename $i`
···
hostElementForVirtualHost = virtualHost: ''
<Host name="${virtualHost.name}" appBase="virtualhosts/${virtualHost.name}/webapps"
unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
+
'' + lib.concatStrings (innerElementsForVirtualHost virtualHost) + ''
innerElementsForVirtualHost = virtualHost:
+
++ (lib.optional cfg.logPerVirtualHost ''
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/${virtualHost.name}"
prefix="${virtualHost.name}_access_log." pattern="combined" resolveHosts="false"/>
+
hostElementsString = lib.concatMapStringsSep "\n" hostElementForVirtualHost cfg.virtualHosts;
+
hostElementsSedString = lib.replaceStrings ["\n"] ["\\\n"] hostElementsString;
# Create a modified server.xml which also includes all virtual hosts
+
sed -e "/<Engine name=\"Catalina\" defaultHost=\"localhost\">/a\\"${lib.escapeShellArg hostElementsSedString} \
${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml
+
${lib.optionalString (cfg.logDirs != []) ''
for i in ${toString cfg.logDirs}; do
mkdir -p ${cfg.baseDir}/logs/$i
chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs/$i
+
${lib.optionalString cfg.logPerVirtualHost (toString (map (h: ''
mkdir -p ${cfg.baseDir}/logs/${h.name}
chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs/${h.name}
···
# Symlink all the given web applications files or paths into the webapps/ directory
+
for i in "${lib.optionalString (virtualHost ? webapps) (toString virtualHost.webapps)}"; do
# If the given web application is a file, symlink it into the webapps/ directory
ln -sfn $i ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps/`basename $i`
···
+
${lib.optionalString cfg.axis2.enable ''
# Copy the Axis2 web application
cp -av ${pkgs.axis2}/webapps/axis2 ${cfg.baseDir}/webapps
···
PermissionsStartOnly = true;
+
PIDFile = "/run/tomcat/tomcat.pid";
RuntimeDirectory = "tomcat";
"CATALINA_BASE=${cfg.baseDir}"
"CATALINA_PID=/run/tomcat/tomcat.pid"