{ lib, pkgs, config, ... }: let cfg = config.this.apache; inherit (lib.attrsets) mergeAttrsList; inherit (builtins) map readFile pathExists; in { options = { this.apache = { enable = lib.mkEnableOption "the Apache HTTP Server"; vhosts = lib.mkOption { type = with lib.types; listOf str; default = []; }; }; }; config = lib.mkIf cfg.enable { services.httpd = { enable = true; logPerVirtualHost = false; logDir = "/var/log/apache2"; virtualHosts = mergeAttrsList (map (name: { "${name}" = { extraConfig = readFile ./${name}.conf; } // (if pathExists ./${name}.nix then import ./${name}.nix { inherit lib pkgs config; } else {});}) cfg.vhosts); }; }; }