From 5e16e671ea1860fb3928d8c50ebd7c30ba182002 Mon Sep 17 00:00:00 2001 From: Pavel Goran Date: Sun, 23 Sep 2018 21:41:35 +0700 Subject: nixos/tomcat: add aliases sub-option for virtual hosts --- nixos/modules/services/web-servers/tomcat.nix | 31 +++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'nixos') diff --git a/nixos/modules/services/web-servers/tomcat.nix b/nixos/modules/services/web-servers/tomcat.nix index d92ba72a833..be54e9255c7 100644 --- a/nixos/modules/services/web-servers/tomcat.nix +++ b/nixos/modules/services/web-servers/tomcat.nix @@ -121,6 +121,11 @@ in type = types.str; description = "name of the virtualhost"; }; + aliases = mkOption { + type = types.listOf types.str; + description = "aliases of the virtualhost"; + default = []; + }; webapps = mkOption { type = types.listOf types.path; description = '' @@ -220,10 +225,28 @@ in ${if cfg.serverXml != "" then '' cp -f ${pkgs.writeTextDir "server.xml" cfg.serverXml}/* ${cfg.baseDir}/conf/ - '' else '' - # Create a modified server.xml which also includes all virtual hosts - sed -e "//a\ ${toString (map (virtualHost: ''${if cfg.logPerVirtualHost then '''' else ""}'') cfg.virtualHosts)}" \ - ${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml + '' else + let + hostElementForVirtualHost = virtualHost: '' + + '' + concatStrings (innerElementsForVirtualHost virtualHost) + '' + + ''; + innerElementsForVirtualHost = virtualHost: + (map (alias: '' + ${alias} + '') virtualHost.aliases) + ++ (optional cfg.logPerVirtualHost '' + + ''); + 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 "//a\\"${escapeShellArg hostElementsSedString} \ + ${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml '' } ${optionalString (cfg.logDirs != []) '' -- cgit 1.4.1