Merge branch 'feature/shortcutdomain' into 'main'

Draft: shortcut domains for services

See merge request hacc/infra/haccfiles!61
keep-around/4706e538ec4ea82a4ef50244c9eeaf9dac279f33
stuebinm 2021-09-20 18:08:36 +00:00
commit 4706e538ec
2 changed files with 53 additions and 0 deletions

View File

@ -21,6 +21,7 @@
../../services/gitlab-runner.nix
../../services/unifi.nix
../../services/lantifa.nix
../../services/shortdomains.nix
./lxc.nix
];

52
services/shortdomains.nix Normal file
View File

@ -0,0 +1,52 @@
{ 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>
'';
};
};
}