Merge pull request #47224 from pvgoran/tomcat-virtualhost-aliases
nixos/tomcat: add aliases sub-option for virtual hosts
This commit is contained in:
commit
3491dd06a1
@ -121,6 +121,11 @@ in
|
|||||||
type = types.str;
|
type = types.str;
|
||||||
description = "name of the virtualhost";
|
description = "name of the virtualhost";
|
||||||
};
|
};
|
||||||
|
aliases = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
description = "aliases of the virtualhost";
|
||||||
|
default = [];
|
||||||
|
};
|
||||||
webapps = mkOption {
|
webapps = mkOption {
|
||||||
type = types.listOf types.path;
|
type = types.listOf types.path;
|
||||||
description = ''
|
description = ''
|
||||||
@ -220,10 +225,28 @@ in
|
|||||||
|
|
||||||
${if cfg.serverXml != "" then ''
|
${if cfg.serverXml != "" then ''
|
||||||
cp -f ${pkgs.writeTextDir "server.xml" cfg.serverXml}/* ${cfg.baseDir}/conf/
|
cp -f ${pkgs.writeTextDir "server.xml" cfg.serverXml}/* ${cfg.baseDir}/conf/
|
||||||
'' else ''
|
'' else
|
||||||
# Create a modified server.xml which also includes all virtual hosts
|
let
|
||||||
sed -e "/<Engine name=\"Catalina\" defaultHost=\"localhost\">/a\ ${toString (map (virtualHost: ''<Host name=\"${virtualHost.name}\" appBase=\"virtualhosts/${virtualHost.name}/webapps\" unpackWARs=\"true\" autoDeploy=\"true\" xmlValidation=\"false\" xmlNamespaceAware=\"false\" >${if cfg.logPerVirtualHost then ''<Valve className=\"org.apache.catalina.valves.AccessLogValve\" directory=\"logs/${virtualHost.name}\" prefix=\"${virtualHost.name}_access_log.\" pattern=\"combined\" resolveHosts=\"false\"/>'' else ""}</Host>'') cfg.virtualHosts)}" \
|
hostElementForVirtualHost = virtualHost: ''
|
||||||
${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml
|
<Host name="${virtualHost.name}" appBase="virtualhosts/${virtualHost.name}/webapps"
|
||||||
|
unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
|
||||||
|
'' + concatStrings (innerElementsForVirtualHost virtualHost) + ''
|
||||||
|
</Host>
|
||||||
|
'';
|
||||||
|
innerElementsForVirtualHost = virtualHost:
|
||||||
|
(map (alias: ''
|
||||||
|
<Alias>${alias}</Alias>
|
||||||
|
'') virtualHost.aliases)
|
||||||
|
++ (optional cfg.logPerVirtualHost ''
|
||||||
|
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/${virtualHost.name}"
|
||||||
|
prefix="${virtualHost.name}_access_log." pattern="combined" resolveHosts="false"/>
|
||||||
|
'');
|
||||||
|
hostElementsString = concatMapStringsSep "\n" hostElementForVirtualHost cfg.virtualHosts;
|
||||||
|
hostElementsSedString = replaceStrings ["\n"] ["\\\n"] hostElementsString;
|
||||||
|
in ''
|
||||||
|
# Create a modified server.xml which also includes all virtual hosts
|
||||||
|
sed -e "/<Engine name=\"Catalina\" defaultHost=\"localhost\">/a\\"${escapeShellArg hostElementsSedString} \
|
||||||
|
${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml
|
||||||
''
|
''
|
||||||
}
|
}
|
||||||
${optionalString (cfg.logDirs != []) ''
|
${optionalString (cfg.logDirs != []) ''
|
||||||
|
Loading…
Reference in New Issue
Block a user