{ config, pkgs, lib, mkDomain, allSubdomains, ... }:
let
  # TODO: support fully qualified urls as well
  customDescriptions = rec {
    index                     = "This page";
    "links.pbsds.net"         = "Linktree";
    "i.kuklef.se"             = pkgs.microbin.meta.description;
    www                       = "wwwwwwwwwwwwwww";
    ${config.networking.fqdn} = www;

    refleksjon    = "My dad is a cheapskate";
    roroslyd      = "My dad is a cheapskate";

    docs          = "Various documentation";
    element       = pkgs.element-web.meta.description;
    shlink        = "Url shortener";

    head          = pkgs.headscale.meta.description;
  };
in
{
  # list of other endpoints hosted with nginx
  # it assumes the owest subdomain equals a package name in pkgs or python3.pkgs.

  services.nginx.virtualHosts.${mkDomain "index"} = {
    forceSSL = true; # addSSL = true;
    enableACME = true; #useACMEHost = acmeDomain;
    root = with lib; let
      getName   = domain: head (lib.splitString "." domain);
      getDomain = domain: concatStringsSep "." (tail (lib.splitString "." domain));
      getDesc   = domain:
        let
          name = getName domain;
        in
          if lib.hasAttr domain customDescriptions
            then customDescriptions.${domain}
          else if lib.hasAttr name customDescriptions
            then customDescriptions.${name}
          else if lib.hasAttr name pkgs
            then pkgs.${name}.meta.description
          else if lib.hasAttr name pkgs.python3Packages
            then pkgs.python3Packages.${name}.meta.description
          else if lib.hasAttrByPath [name "package"] config.services
            then config.services.${name}.package.meta.description
          else "";
      mkRow = domain: ''<tr><td><a href="//${domain}">${getName domain}<span style="opacity: 0.65;">.${getDomain domain}</span></a><td>${getDesc domain}'';
    in pkgs.writeTextDir "index.html" ''
      <!DOCTYPE html>
      <table>
      <tr><th>url<th>description
      ${lib.concatStringsSep "\n" (map mkRow allSubdomains)}
      </table>
    '';
  };

}