<commit_before>{config, pkgs}:

let

  cfg = config.services.httpd;

  mainCfg = cfg;
  
  startingDependency = if config.services.gw6c.enable then "gw6c" else "network-interfaces";

  httpd = pkgs.apacheHttpd;

  inherit (pkgs.lib) addDefaultOptionValues optional concatMap concatMapStrings;
  

  makeServerInfo = cfg: {
    # Canonical name must not include a trailing slash.
    canonicalName =
      "http://${cfg.hostName}" +
      (if cfg.httpPort != 80 then ":${toString cfg.httpPort}" else "");

    # Admin address: inherit from the main server if not specified for
    # a virtual host.
    adminAddr = if cfg.adminAddr != "" then cfg.adminAddr else mainCfg.adminAddr;

    vhostConfig = cfg;
    serverConfig = mainCfg;
    fullConfig = config; # machine config
  };


  vhostOptions = import ./per-server-options.nix {
    inherit (pkgs.lib) mkOption;
    forMainServer = false;
  };

  vhosts = let
    makeVirtualHost = cfgIn: 
      let
        # Fill in defaults for missing options.
        cfg = addDefaultOptionValues vhostOptions cfgIn;
      in cfg;
    in map makeVirtualHost cfg.virtualHosts;


  callSubservices = serverInfo: defs:
    let f = svc:
      let config = addDefaultOptionValues res.options svc.config;
          res = svc.function {inherit config pkgs serverInfo;};
      in res;
    in map f defs;


  # !!! callSubservices is expensive   
  subservicesFor = cfg: callSubservices (makeServerInfo cfg) cfg.extraSubservices;

  mainSubservices = subservicesFor mainCfg;

  allSubservices = mainSubservices ++ pkgs.lib.concatMap subservicesFor vhosts;

  sslServerCert = cfg.sslServerCert;
  sslServerKey = cfg.sslServerKey;

  # !!! should be in lib
  writeTextInDir = name: text:
    pkgs.runCommand name {inherit text;} "ensureDir $out; echo -n \"$text\" > $out/$name";
  

  # Names of modules from ${httpd}/modules that we want to load.
  apacheModules = 
    [ # HTTP authentication mechanisms: basic and digest.
      "auth_basic" "auth_digest"<commit_msg>Added possibility to use names instead of full paths in httpd subservices. Yes, the same dirty hack again<commit_after>{config, pkgs}:

let

  cfg = config.services.httpd;

  mainCfg = cfg;
  
  startingDependency = if config.services.gw6c.enable then "gw6c" else "network-interfaces";

  httpd = pkgs.apacheHttpd;

  inherit (pkgs.lib) addDefaultOptionValues optional concatMap concatMapStrings;
  

  makeServerInfo = cfg: {
    # Canonical name must not include a trailing slash.
    canonicalName =
      "http://${cfg.hostName}" +
      (if cfg.httpPort != 80 then ":${toString cfg.httpPort}" else "");

    # Admin address: inherit from the main server if not specified for
    # a virtual host.
    adminAddr = if cfg.adminAddr != "" then cfg.adminAddr else mainCfg.adminAddr;

    vhostConfig = cfg;
    serverConfig = mainCfg;
    fullConfig = config; # machine config
  };


  vhostOptions = import ./per-server-options.nix {
    inherit (pkgs.lib) mkOption;
    forMainServer = false;
  };

  vhosts = let
    makeVirtualHost = cfgIn: 
      let
        # Fill in defaults for missing options.
        cfg = addDefaultOptionValues vhostOptions cfgIn;
      in cfg;
    in map makeVirtualHost cfg.virtualHosts;


  callSubservices = serverInfo: defs:
    let f = svc:
      let 
        svcFunction = if svc ? function then 
          svc.function else (import ( ./noDir/.. + ("/" + svc.serviceName + ".nix")));
        config = addDefaultOptionValues res.options svc.config;
        res = svcFunction {inherit config pkgs serverInfo;};
      in res;
    in map f defs;


  # !!! callSubservices is expensive   
  subservicesFor = cfg: callSubservices (makeServerInfo cfg) cfg.extraSubservices;

  mainSubservices = subservicesFor mainCfg;

  allSubservices = mainSubservices ++ pkgs.lib.concatMap subservicesFor vhosts;

  sslServerCert = cfg.sslServerCert;
  sslServerKey = cfg.sslServerKey;

  # !!! should be in lib
  writeTextInDir = name: text:
    pkgs.runCommand name {inherit text;} "ensureDir $out; echo -n \"$text\" > $out/$name";
  

  # Names of modules from ${httpd}/modules that we want to load.
  apacheModules = 
    [ # HTTP authentication mechanisms: basic and digest.
      "auth_basic" "auth_digest"
{'fraction_non_alphanumeric': 0.09600378340033104, 'fraction_numerical': 0.0018917001655237645, 'mean_word_length': 3.126829268292683, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '806659', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1259, 'n_words': 385}