anchor.diff:        };
   
         virtualHosts = mkOption {
  +        type = types.listOf (types.submodule {
  +          options = {
  +            name = mkOption {
  +              type = types.listOf types.str;
  +              description = "name of the virtualhost";
  +              default = [];
  +            };
  +          };
  +        });
           default = [];
           description = "List consisting of a virtual host name and a list of web applications to deploy on each virtual host";
         };
   
         logPerVirtualHost = mkOption {
  +        type = types.bool;
           default = false;
           description = "Whether to enable logging per virtual host.";
         };
  
positive.code:       description = "Apache Tomcat server";
        wantedBy = [ "multi-user.target" ];
        after = [ "network.target" ];
        serviceConfig.Type = "oneshot";
        serviceConfig.RemainAfterExit = true;
  
        preStart = ''
          # Create the base directory
          mkdir -p ${cfg.baseDir}
  
          mkdir -p ${cfg.baseDir}
  
          # Create a symlink to the bin directory of the tomcat component
          ln -sfn ${tomcat}/bin ${cfg.baseDir}/bin
  
          # Create a conf/ directory
          mkdir -p ${cfg.baseDir}/conf
          chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/conf
  
          # Symlink the config files in the conf/ directory (except for catalina.properties and server.xml)
          for i in $(ls ${tomcat}/conf | grep -v catalina.properties | grep -v server.xml)
          do
              ln -sfn ${tomcat}/conf/$i ${cfg.baseDir}/conf/`basename $i`
          done
  
          ${if cfg.extraConfigFiles != [] then ''
            for i in ${toString cfg.extraConfigFiles}
            do
              ln -sfn $i ${cfg.baseDir}/conf/`basename $i`
            done
          '' else ""}
  
          # Create subdirectory for virtual hosts
          mkdir -p ${cfg.baseDir}/virtualhosts
  
          # Create a modified catalina.properties file
          # Change all references from CATALINA_HOME to CATALINA_BASE and add support for shared libraries
          sed -e 's|''${catalina.home}|''${catalina.base}|g' \
              -e 's|shared.loader=|shared.loader=''${catalina.base}/shared/lib/*.jar|' \
              ${tomcat}/conf/catalina.properties > ${cfg.baseDir}/conf/catalina.properties
  
          ${if cfg.serverXml != "" then ''
            cat <<'EOF' > ${cfg.baseDir}/conf/server.xml
            ${cfg.serverXml}EOF
            '' else ''
            # Create a modified server.xml which also includes all virtual hosts
            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)}" \
                  ${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml
            ''
          }
          # Create a logs/ directory
          mkdir -p ${cfg.baseDir}/logs
          chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs
          ${if cfg.logDirs != [] then ''
              for i in ${toString cfg.logDirs}; do
                  mkdir -p ${cfg.baseDir}/logs/$i
                  chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs/$i
              done
          '' else ""}
          ${if cfg.logPerVirtualHost then
             toString (map (h: ''
                                  mkdir -p ${cfg.baseDir}/logs/${h.name}
                                  chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs/${h.name}
                               '') cfg.virtualHosts) else ''''}
  
          # Create a temp/ directory
          mkdir -p ${cfg.baseDir}/temp
          chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/temp
  
          # Create a lib/ directory
          mkdir -p ${cfg.baseDir}/lib
          chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/lib
  
          # Create a shared/lib directory
          mkdir -p ${cfg.baseDir}/shared/lib
          chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/shared/lib
  
          # Create a webapps/ directory
          mkdir -p ${cfg.baseDir}/webapps
          chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/webapps
  
          # Symlink all the given common libs files or paths into the lib/ directory
          for i in ${tomcat} ${toString cfg.commonLibs}
          do
              if [ -f $i ]
              then
                  # If the given web application is a file, symlink it into the common/lib/ directory
                  ln -sfn $i ${cfg.baseDir}/lib/`basename $i`
              elif [ -d $i ]
              then
                  # If the given web application is a directory, then iterate over the files
                  # in the special purpose directories and symlink them into the tomcat tree
  
                  for j in $i/lib/*
                  do
                      ln -sfn $j ${cfg.baseDir}/lib/`basename $j`
                  done
              fi
          done
  
          # Symlink all the given shared libs files or paths into the shared/lib/ directory
          for i in ${toString cfg.sharedLibs}
          do
              if [ -f $i ]
              then
                  # If the given web application is a file, symlink it into the common/lib/ directory
                  ln -sfn $i ${cfg.baseDir}/shared/lib/`basename $i`
              elif [ -d $i ]
              then
                  # If the given web application is a directory, then iterate over the files
                  # in the special purpose directories and symlink them into the tomcat tree
  
                  for j in $i/shared/lib/*
                  do
                      ln -sfn $j ${cfg.baseDir}/shared/lib/`basename $j`
                  done
              fi
          done
  
          # Symlink all the given web applications files or paths into the webapps/ directory
          for i in ${toString cfg.webapps}
          do
              if [ -f $i ]
              then
                  # If the given web application is a file, symlink it into the webapps/ directory
                  ln -sfn $i ${cfg.baseDir}/webapps/`basename $i`
              elif [ -d $i ]
              then
                  # If the given web application is a directory, then iterate over the files
                  # in the special purpose directories and symlink them into the tomcat tree
  
                  for j in $i/webapps/*
                  do
                      ln -sfn $j ${cfg.baseDir}/webapps/`basename $j`
                  done
  
                  # Also symlink the configuration files if they are included
                  if [ -d $i/conf/Catalina ]
                  then
                      for j in $i/conf/Catalina/*
                      do
                          mkdir -p ${cfg.baseDir}/conf/Catalina/localhost
                          ln -sfn $j ${cfg.baseDir}/conf/Catalina/localhost/`basename $j`
                      done
                  fi
              fi
          done
  
          ${toString (map (virtualHost: ''
  
negative.code:       };
  
        baseDir = mkOption {
          type = lib.types.path;
          default = "/var/tomcat";
          description = "Location where Tomcat stores configuration files, webapplications and logfiles";
        };
  
        logDirs = mkOption {
          default = [];
          type = types.listOf types.path;
          description = "Directories to create in baseDir/logs/";
        };
  
        extraConfigFiles = mkOption {
          default = [];
          type = types.listOf types.path;
          description = "Extra configuration files to pull into the tomcat conf directory";
        };
  
        extraEnvironment = mkOption {
          type = types.listOf types.str;
          default = [];
          example = [ "ENVIRONMENT=production" ];
          description = "Environment Variables to pass to the tomcat service";
        };
  
        extraGroups = mkOption {
  