config/profiles/web/index/default.nix

55 lines
2.0 KiB
Nix
Raw Normal View History

2023-02-25 00:03:29 +01:00
{ config, pkgs, lib, mkDomain, allSubdomains, ... }:
let
# TODO: support fully qualified urls as well
customDescriptions = rec {
2023-06-26 21:03:25 +02:00
index = "This page";
"links.pbsds.net" = "Linktree";
"i.kuklef.se" = pkgs.microbin.meta.description;
www = "wwwwwwwwwwwwwww";
${config.networking.fqdn} = www;
2023-02-25 00:03:29 +01:00
refleksjon = "My dad is a cheapskate";
roroslyd = "My dad is a cheapskate";
2023-06-26 21:03:25 +02:00
2023-02-26 03:53:55 +01:00
docs = "Various documentation";
2023-06-26 21:03:25 +02:00
element = pkgs.element-web.meta.description;
shlink = "Url shortener";
2023-02-25 00:03:29 +01:00
};
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));
2023-06-26 21:03:25 +02:00
getDesc = domain:
let
2023-02-25 00:03:29 +01:00
name = getName domain;
2023-06-26 21:03:25 +02:00
in
if lib.hasAttr domain customDescriptions
then customDescriptions.${domain}
else if lib.hasAttr name customDescriptions
2023-02-25 00:03:29 +01:00
then customDescriptions.${name}
else if lib.hasAttr name pkgs
then pkgs.${name}.meta.description
2023-06-26 21:03:25 +02:00
else if lib.hasAttr name pkgs.python3Packages
then pkgs.python3Packages.${name}.meta.description
2023-02-25 00:03:29 +01:00
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>
'';
};
}