summaryrefslogtreecommitdiff
path: root/modules/apache/default.nix
blob: d581aca85cd9079d13f69651e5adcfbbe3c32742 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{ 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);
    };
  };
}