haccfiles/services/shortdomains.nix
stuebinm 9eed435ea3
shortcutdomains: generate an index page
misusing nix as an html templating language, yay!

We could (and maybe should) also use something more reasonable instead,
e.g. jekyll or hakyll, but for a simple listing nix turns out to be
quite enough.

The page doesn't look all too well for now; I haven't set any css, or
even added some <div>-tags for basic styling.
2021-10-07 17:50:54 +02:00

52 lines
1.3 KiB
Nix

{ config, lib, pkgs, ... }:
let
shortdomain = "i4f.de";
short = name: target: {
inherit name target;
};
toVirtualHosts = {name, target, ...}: {
name = "${name}.${shortdomain}";
value = {
forceSSL = true;
enableACME = true;
locations."/".return = "302 https://${target}$request_uri";
};
};
redirects = [
(short "d" "discuss.infra4future.de")
(short "m" "mattermost.infra4future.de")
(short "c" "cloud.infra4future.de")
(short "s" "survey.infra4future.de")
(short "g" "gitlab.infra4future.de")
];
in
{
services.nginx.virtualHosts =
lib.listToAttrs (map toVirtualHosts redirects)
// {
${shortdomain} = {
enableACME = true;
forceSSL = true;
root = pkgs.writeText "index.html" ''
<html lang="en">
<head>
<title>Infra4future shortlinks</title>
<meta charset="UTF-8">
</head>
<body><h1>Shortlinks for infra4future.de</h1>
${lib.strings.concatStrings
(map ({name, target,...}:
''
<p>
<a href="https://${target}">${name}.${shortdomain} ${target}</a>
</p>
'')
redirects)
}
</body>
</html>
'';
};
};
}