···
{ config, lib, pkgs, ... }:
cfg = config.services.tomcat;
···
14
-
maintainers = with maintainers; [ danbst ];
11
+
maintainers = with lib.maintainers; [ danbst ];
22
-
enable = mkEnableOption (lib.mdDoc "Apache Tomcat");
18
+
enable = lib.mkEnableOption (lib.mdDoc "Apache Tomcat");
24
-
package = mkOption {
25
-
type = types.package;
26
-
default = pkgs.tomcat9;
27
-
defaultText = literalExpression "pkgs.tomcat9";
28
-
example = lib.literalExpression "pkgs.tomcat9";
29
-
description = lib.mdDoc ''
30
-
Which tomcat package to use.
20
+
package = lib.mkPackageOptionMD pkgs "tomcat9" { };
34
-
purifyOnStart = mkOption {
22
+
purifyOnStart = lib.mkOption {
23
+
type = lib.types.bool;
description = lib.mdDoc ''
On startup, the `baseDir` directory is populated with various files,
···
46
-
baseDir = mkOption {
34
+
baseDir = lib.mkOption {
description = lib.mdDoc ''
···
56
-
logDirs = mkOption {
58
-
type = types.listOf types.path;
44
+
logDirs = lib.mkOption {
46
+
type = lib.types.listOf lib.types.path;
description = lib.mdDoc "Directories to create in baseDir/logs/";
62
-
extraConfigFiles = mkOption {
64
-
type = types.listOf types.path;
50
+
extraConfigFiles = lib.mkOption {
52
+
type = lib.types.listOf lib.types.path;
description = lib.mdDoc "Extra configuration files to pull into the tomcat conf directory";
68
-
extraEnvironment = mkOption {
69
-
type = types.listOf types.str;
56
+
extraEnvironment = lib.mkOption {
57
+
type = lib.types.listOf lib.types.str;
example = [ "ENVIRONMENT=production" ];
description = lib.mdDoc "Environment Variables to pass to the tomcat service";
75
-
extraGroups = mkOption {
77
-
type = types.listOf types.str;
63
+
extraGroups = lib.mkOption {
65
+
type = lib.types.listOf lib.types.str;
description = lib.mdDoc "Defines extra groups to which the tomcat user belongs.";
70
+
user = lib.mkOption {
71
+
type = lib.types.str;
description = lib.mdDoc "User account under which Apache Tomcat runs.";
76
+
group = lib.mkOption {
77
+
type = lib.types.str;
description = lib.mdDoc "Group account under which Apache Tomcat runs.";
94
-
javaOpts = mkOption {
95
-
type = types.either (types.listOf types.str) types.str;
82
+
javaOpts = lib.mkOption {
83
+
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";
100
-
catalinaOpts = mkOption {
101
-
type = types.either (types.listOf types.str) types.str;
88
+
catalinaOpts = lib.mkOption {
89
+
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";
106
-
sharedLibs = mkOption {
107
-
type = types.listOf types.str;
94
+
sharedLibs = lib.mkOption {
95
+
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";
112
-
serverXml = mkOption {
113
-
type = types.lines;
100
+
serverXml = lib.mkOption {
101
+
type = lib.types.lines;
description = lib.mdDoc ''
Verbatim server.xml configuration.
···
121
-
commonLibs = mkOption {
122
-
type = types.listOf types.str;
109
+
commonLibs = lib.mkOption {
110
+
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";
127
-
webapps = mkOption {
128
-
type = types.listOf types.path;
115
+
webapps = lib.mkOption {
116
+
type = lib.types.listOf lib.types.path;
default = [ tomcat.webapps ];
130
-
defaultText = literalExpression "[ config.services.tomcat.package.webapps ]";
118
+
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";
134
-
virtualHosts = mkOption {
135
-
type = types.listOf (types.submodule {
122
+
virtualHosts = lib.mkOption {
123
+
type = lib.types.listOf (lib.types.submodule {
125
+
name = lib.mkOption {
126
+
type = lib.types.str;
description = lib.mdDoc "name of the virtualhost";
141
-
aliases = mkOption {
142
-
type = types.listOf types.str;
129
+
aliases = lib.mkOption {
130
+
type = lib.types.listOf lib.types.str;
description = lib.mdDoc "aliases of the virtualhost";
146
-
webapps = mkOption {
147
-
type = types.listOf types.path;
134
+
webapps = lib.mkOption {
135
+
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";
160
-
logPerVirtualHost = mkOption {
148
+
logPerVirtualHost = lib.mkOption {
149
+
type = lib.types.bool;
description = lib.mdDoc "Whether to enable logging per virtual host.";
167
-
type = types.package;
168
-
default = pkgs.jdk;
169
-
defaultText = literalExpression "pkgs.jdk";
170
-
description = lib.mdDoc "Which JDK to use.";
154
+
jdk = lib.mkPackageOptionMD pkgs "jdk" { };
175
-
enable = mkOption {
178
-
description = lib.mdDoc "Whether to enable an Apache Axis2 container";
157
+
enable = lib.mkEnableOption "Apache Axis2 container";
181
-
services = mkOption {
183
-
type = types.listOf types.str;
159
+
services = lib.mkOption {
161
+
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";
196
-
config = mkIf config.services.tomcat.enable {
170
+
config = lib.mkIf config.services.tomcat.enable {
users.groups.tomcat.gid = config.ids.gids.tomcat;
201
-
{ uid = config.ids.uids.tomcat;
176
+
uid = config.ids.uids.tomcat;
description = "Tomcat user";
home = "/homeless-shelter";
···
ln -sfn ${tomcat}/conf/$i ${cfg.baseDir}/conf/`basename $i`
237
-
${optionalString (cfg.extraConfigFiles != []) ''
212
+
${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">
256
-
'' + concatStrings (innerElementsForVirtualHost virtualHost) + ''
231
+
'' + lib.concatStrings (innerElementsForVirtualHost virtualHost) + ''
innerElementsForVirtualHost = virtualHost:
263
-
++ (optional cfg.logPerVirtualHost ''
238
+
++ (lib.optional cfg.logPerVirtualHost ''
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/${virtualHost.name}"
prefix="${virtualHost.name}_access_log." pattern="combined" resolveHosts="false"/>
267
-
hostElementsString = concatMapStringsSep "\n" hostElementForVirtualHost cfg.virtualHosts;
268
-
hostElementsSedString = replaceStrings ["\n"] ["\\\n"] hostElementsString;
242
+
hostElementsString = lib.concatMapStringsSep "\n" hostElementForVirtualHost cfg.virtualHosts;
243
+
hostElementsSedString = lib.replaceStrings ["\n"] ["\\\n"] hostElementsString;
# Create a modified server.xml which also includes all virtual hosts
271
-
sed -e "/<Engine name=\"Catalina\" defaultHost=\"localhost\">/a\\"${escapeShellArg hostElementsSedString} \
246
+
sed -e "/<Engine name=\"Catalina\" defaultHost=\"localhost\">/a\\"${lib.escapeShellArg hostElementsSedString} \
${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml
275
-
${optionalString (cfg.logDirs != []) ''
250
+
${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
281
-
${optionalString cfg.logPerVirtualHost (toString (map (h: ''
256
+
${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
348
-
for i in "${optionalString (virtualHost ? webapps) (toString virtualHost.webapps)}"; do
323
+
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`
···
371
-
${optionalString cfg.axis2.enable ''
346
+
${lib.optionalString cfg.axis2.enable ''
# Copy the Axis2 web application
cp -av ${pkgs.axis2}/webapps/axis2 ${cfg.baseDir}/webapps
···
PermissionsStartOnly = true;
408
-
PIDFile="/run/tomcat/tomcat.pid";
383
+
PIDFile = "/run/tomcat/tomcat.pid";
RuntimeDirectory = "tomcat";
"CATALINA_BASE=${cfg.baseDir}"
"CATALINA_PID=/run/tomcat/tomcat.pid"