git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #47224 from pvgoran/tomcat-virtualhost-aliases

nixos/tomcat: add aliases sub-option for virtual hosts

commit3491dd06a186db0b208d23d07c1d16c9b51d895c authorMichael Raskin <7c6f434c@mail.ru> dateSun 21 Oct 2018, 07:54 (8 years ago) parentd88d0125e16e67
1 file changed+27−4
nixos/modules/services/web-servers/tomcat.nix+27−4
nixos/modules/services/web-servers/tomcat.nix+27−4
@@ -121,6 +121,11 @@ in
121121 type = types.str;
122122 description = "name of the virtualhost";
123123 };
124+ aliases = mkOption {
125+ type = types.listOf types.str;
126+ description = "aliases of the virtualhost";
127+ default = [];
128+ };
124129 webapps = mkOption {
125130 type = types.listOf types.path;
126131 description = ''
@@ -220,10 +225,28 @@ in
220225
221226 ${if cfg.serverXml != "" then ''
222227 cp -f ${pkgs.writeTextDir "server.xml" cfg.serverXml}/* ${cfg.baseDir}/conf/
223− '' else ''
224− # Create a modified server.xml which also includes all virtual hosts
225− 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)}" \
226− ${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml
228+ '' else
229+ let
230+ hostElementForVirtualHost = virtualHost: ''
231+ <Host name="${virtualHost.name}" appBase="virtualhosts/${virtualHost.name}/webapps"
232+ unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
233+ '' + concatStrings (innerElementsForVirtualHost virtualHost) + ''
234+ </Host>
235+ '';
236+ innerElementsForVirtualHost = virtualHost:
237+ (map (alias: ''
238+ <Alias>${alias}</Alias>
239+ '') virtualHost.aliases)
240+ ++ (optional cfg.logPerVirtualHost ''
241+ <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/${virtualHost.name}"
242+ prefix="${virtualHost.name}_access_log." pattern="combined" resolveHosts="false"/>
243+ '');
244+ hostElementsString = concatMapStringsSep "\n" hostElementForVirtualHost cfg.virtualHosts;
245+ hostElementsSedString = replaceStrings ["\n"] ["\\\n"] hostElementsString;
246+ in ''
247+ # Create a modified server.xml which also includes all virtual hosts
248+ sed -e "/<Engine name=\"Catalina\" defaultHost=\"localhost\">/a\\"${escapeShellArg hostElementsSedString} \
249+ ${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml
227250 ''
228251 }
229252 ${optionalString (cfg.logDirs != []) ''