blob: 66ced1d0d13ae8053d5299f9a79acca049fb5677 [file] [log] [blame]
# SPDX-FileCopyrightText: 2024 Clicks Codes
#
# SPDX-License-Identifier: GPL-3.0-only
{ lib, ... }: let
step0 = {
"calibre.clicks.codes" = {
service = lib.pipe (lib.clicks.nginx.http.reverseProxy "generic" 1024) [
lib.clicks.nginx.http.unsafeAddCrossOriginHeader
(lib.clicks.nginx.http.addHeader "X-Clacks-Overhead" "GNU Terry Pratchett")
];
www = true;
dnsProvider = "cloudflare";
routes = null;
authWith = "tailscale";
enableHttp = false;
};
};
step1 = {
"calibre.clicks.codes" = {
service = {
_type = "header";
name = "X-Clacks-Overhead";
value = "GNU Terry Pratchett";
content = {
_type = "header";
name = "Access-Control-Allow-Origin";
value = "*";
content = {
host = "generic";
port = 1024;
protocol = "http";
_type = "reverseProxy";
headers = null;
};
};
};
dnsProvider = "cloudflare";
routes = null;
authWith = "tailscale";
enableHttp = false;
};
"www.calibre.clicks.codes" = {
routes."~ ^/?([^\r\n]*)$" = lib.home-manager.hm.dag.entryAnywhere {
to = "https://calibre.clicks.codes/$1";
permanent = true;
_type = "redirect";
headers = null;
};
authWith = null;
service = null;
enableHttp = false;
};
};
step2 = {
"calibre.clicks.codes" = {
routes."/" = lib.home-manager.hm.dag.entryAnywhere {
_type = "header";
name = "X-Clacks-Overhead";
value = "GNU Terry Pratchett";
content = {
_type = "header";
name = "Access-Control-Allow-Origin";
value = "*";
content = {
host = "generic";
port = 1024;
protocol = "http";
_type = "reverseProxy";
headers = null;
};
};
};
dnsProvider = "cloudflare";
authWith = "tailscale";
enableHttp = false;
};
"www.calibre.clicks.codes" = {
routes."~ ^/?([^\r\n]*)$" = lib.home-manager.hm.dag.entryAnywhere {
to = "https://calibre.clicks.codes/$1";
permanent = true;
_type = "redirect";
headers = null;
};
authWith = null;
enableHttp = false;
};
};
step3 = {
"calibre.clicks.codes" = {
routes = [
{
name = "/";
value = {
_type = "header";
name = "X-Clacks-Overhead";
value = "GNU Terry Pratchett";
content = {
_type = "header";
name = "Access-Control-Allow-Origin";
value = "*";
content = {
host = "generic";
port = 1024;
protocol = "http";
_type = "reverseProxy";
headers = null;
};
};
};
}
];
dnsProvider = "cloudflare";
authWith = "tailscale";
enableHttp = false;
};
"www.calibre.clicks.codes" = {
routes = [
{
name = "~ ^/?([^\r\n]*)$";
value = {
to = "https://calibre.clicks.codes/$1";
permanent = true;
_type = "redirect";
headers = null;
};
}
];
authWith = null;
enableHttp = false;
};
};
step4 = {
"calibre.clicks.codes" = {
routes = [
{
name = "/";
value = {
host = "generic";
port = 1024;
protocol = "http";
_type = "reverseProxy";
headers = {
"Access-Control-Allow-Origin" = "*";
"X-Clacks-Overhead" = "GNU Terry Pratchett";
};
};
}
];
dnsProvider = "cloudflare";
authWith = "tailscale";
enableHttp = false;
};
"www.calibre.clicks.codes" = {
routes = [
{
name = "~ ^/?([^\r\n]*)$";
value = {
to = "https://calibre.clicks.codes/$1";
permanent = true;
_type = "redirect";
headers = null;
};
}
];
authWith = null;
enableHttp = false;
};
};
step5 = {
"calibre.clicks.codes" = {
locations = [
{
name = "/";
value = {
proxyPass = "http://generic:1024";
proxyWebsockets = true;
recommendedProxySettings = true;
extraConfig = "\nadd_header \"X-Clacks-Overhead\" \"GNU Terry Pratchett\";\nadd_header \"Access-Control-Allow-Origin\" \"*\";";
};
}
];
dnsProvider = "cloudflare";
authWith = "tailscale";
enableHttp = false;
};
"www.calibre.clicks.codes" = {
locations = [
{
name = "~ ^/?([^\r\n]*)$";
value = {
return = "307 https://calibre.clicks.codes/$1";
};
}
];
authWith = null;
enableHttp = false;
};
};
step6 = {
"calibre.clicks.codes" = {
locations."/" = {
priority = 100;
proxyPass = "http://generic:1024";
proxyWebsockets = true;
recommendedProxySettings = true;
extraConfig = "\nadd_header \"X-Clacks-Overhead\" \"GNU Terry Pratchett\";\nadd_header \"Access-Control-Allow-Origin\" \"*\";";
};
dnsProvider = "cloudflare";
authWith = "tailscale";
enableHttp = false;
};
"www.calibre.clicks.codes" = {
locations."~ ^/?([^\r\n]*)$" = {
return = "307 https://calibre.clicks.codes/$1";
priority = 100;
};
authWith = null;
enableHttp = false;
};
};
step7 = {
"calibre.clicks.codes" = {
locations."/" = {
priority = 100;
proxyPass = "http://generic:1024";
proxyWebsockets = true;
recommendedProxySettings = true;
extraConfig = "\nadd_header \"X-Clacks-Overhead\" \"GNU Terry Pratchett\";\nadd_header \"Access-Control-Allow-Origin\" \"*\";";
};
onlySSL = true;
addSSL = false;
useACMEHost = "calibre.clicks.codes";
dnsProvider = "cloudflare";
authWith = "tailscale";
};
"www.calibre.clicks.codes" = {
locations."~ ^/?([^\r\n]*)$" = {
return = "307 https://calibre.clicks.codes/$1";
priority = 100;
};
onlySSL = true;
addSSL = false;
useACMEHost = "www.calibre.clicks.codes";
authWith = null;
};
};
in {
testGenerateWwwRedirects = {
expr = lib.clicks.nginx.http.internal.generateWwwRedirects step0;
expected = step1;
};
testTranslateServiceToRoutes = {
expr = lib.clicks.nginx.http.internal.translateServiceToRoutes step1;
expected = step2;
};
testTranslateRoutesDagToList = {
expr = lib.clicks.nginx.http.internal.translateRoutesDagToList step2;
expected = step3;
};
testUnwrapHeader = {
expr = lib.clicks.nginx.http.internal.unwrapHeaders step3;
expected = step4;
};
testTranslateRoutesToLocations = {
expr = lib.clicks.nginx.http.internal.translateRoutesToLocations step4;
expected = step5;
};
testSetLocationPriorities = {
expr = lib.clicks.nginx.http.internal.setLocationPriorities step5;
expected = step6;
};
testAddListenDefaults = {
expr = lib.clicks.nginx.http.internal.addListenDefaults step6;
expected = step7;
};
}