config/profiles/web/index/default.nix

48 lines
1.8 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 {
index = "This page";
links = "Linktree";
element = pkgs.element-web.meta.description;
refleksjon = "My dad is a cheapskate";
roroslyd = "My dad is a cheapskate";
www = "wwwwwwwwwwwwwww";
${config.networking.hostName} = www;
shlink = "Url shortener";
2023-02-26 03:53:55 +01:00
docs = "Various documentation";
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));
getDesc = domain: let
name = getName domain;
in if lib.hasAttr name customDescriptions
then customDescriptions.${name}
else if lib.hasAttr name pkgs.python3Packages
then pkgs.python3Packages.${name}.meta.description
else if lib.hasAttr name pkgs
then pkgs.${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>
'';
};
}