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.
keep-around/5e7c46a4e96150bf22b674d671362ada79a2247d
stuebinm 2021-05-03 12:08:25 +02:00
parent e07d23e2ee
commit 9eed435ea3
No known key found for this signature in database
GPG Key ID: 8FBE8AAD32FA12B7
1 changed files with 35 additions and 5 deletions

View File

@ -2,21 +2,51 @@
let
shortdomain = "i4f.de";
short = abbrv: target: {
name = "${abbrv}.${shortdomain}";
short = name: target: {
inherit name target;
};
toVirtualHosts = {name, target, ...}: {
name = "${name}.${shortdomain}";
value = {
forceSSL = true;
enableACME = true;
locations."/".return = "302 https://${target}$request_uri";
};
};
in
{
services.nginx.virtualHosts = lib.listToAttrs [
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>
'';
};
};
}