From 9eed435ea3b5ba964f19da24e20297aa2ce2fccd Mon Sep 17 00:00:00 2001 From: stuebinm Date: Mon, 3 May 2021 12:08:25 +0200 Subject: [PATCH] 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
-tags for basic styling. --- services/shortdomains.nix | 40 ++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/services/shortdomains.nix b/services/shortdomains.nix index 6c53b95..a1e75f8 100644 --- a/services/shortdomains.nix +++ b/services/shortdomains.nix @@ -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" '' + + + Infra4future shortlinks + + +

Shortlinks for infra4future.de

+ ${lib.strings.concatStrings + (map ({name, target,...}: + '' +

+ ${name}.${shortdomain} → ${target} +

+ '') + redirects) + } + + + ''; + }; + }; }