blob: 66ced1d0d13ae8053d5299f9a79acca049fb5677 [file] [log] [blame]
Skyler Greyd7e1acd2024-06-22 14:42:11 +00001# SPDX-FileCopyrightText: 2024 Clicks Codes
2#
3# SPDX-License-Identifier: GPL-3.0-only
4
5{ lib, ... }: let
6 step0 = {
7 "calibre.clicks.codes" = {
8 service = lib.pipe (lib.clicks.nginx.http.reverseProxy "generic" 1024) [
9 lib.clicks.nginx.http.unsafeAddCrossOriginHeader
10 (lib.clicks.nginx.http.addHeader "X-Clacks-Overhead" "GNU Terry Pratchett")
11 ];
12 www = true;
13 dnsProvider = "cloudflare";
14 routes = null;
15 authWith = "tailscale";
16 enableHttp = false;
17 };
18 };
19 step1 = {
20 "calibre.clicks.codes" = {
21 service = {
22 _type = "header";
23 name = "X-Clacks-Overhead";
24 value = "GNU Terry Pratchett";
25 content = {
26 _type = "header";
27 name = "Access-Control-Allow-Origin";
28 value = "*";
29 content = {
30 host = "generic";
31 port = 1024;
32 protocol = "http";
33 _type = "reverseProxy";
34 headers = null;
35 };
36 };
37 };
38 dnsProvider = "cloudflare";
39 routes = null;
40 authWith = "tailscale";
41 enableHttp = false;
42 };
43 "www.calibre.clicks.codes" = {
44 routes."~ ^/?([^\r\n]*)$" = lib.home-manager.hm.dag.entryAnywhere {
45 to = "https://calibre.clicks.codes/$1";
46 permanent = true;
47 _type = "redirect";
48 headers = null;
49 };
50 authWith = null;
51 service = null;
52 enableHttp = false;
53 };
54 };
55 step2 = {
56 "calibre.clicks.codes" = {
57 routes."/" = lib.home-manager.hm.dag.entryAnywhere {
58 _type = "header";
59 name = "X-Clacks-Overhead";
60 value = "GNU Terry Pratchett";
61 content = {
62 _type = "header";
63 name = "Access-Control-Allow-Origin";
64 value = "*";
65 content = {
66 host = "generic";
67 port = 1024;
68 protocol = "http";
69 _type = "reverseProxy";
70 headers = null;
71 };
72 };
73 };
74 dnsProvider = "cloudflare";
75 authWith = "tailscale";
76 enableHttp = false;
77 };
78 "www.calibre.clicks.codes" = {
79 routes."~ ^/?([^\r\n]*)$" = lib.home-manager.hm.dag.entryAnywhere {
80 to = "https://calibre.clicks.codes/$1";
81 permanent = true;
82 _type = "redirect";
83 headers = null;
84 };
85 authWith = null;
86 enableHttp = false;
87 };
88 };
89 step3 = {
90 "calibre.clicks.codes" = {
91 routes = [
92 {
93 name = "/";
94 value = {
95 _type = "header";
96 name = "X-Clacks-Overhead";
97 value = "GNU Terry Pratchett";
98 content = {
99 _type = "header";
100 name = "Access-Control-Allow-Origin";
101 value = "*";
102 content = {
103 host = "generic";
104 port = 1024;
105 protocol = "http";
106 _type = "reverseProxy";
107 headers = null;
108 };
109 };
110 };
111 }
112 ];
113 dnsProvider = "cloudflare";
114 authWith = "tailscale";
115 enableHttp = false;
116 };
117 "www.calibre.clicks.codes" = {
118 routes = [
119 {
120 name = "~ ^/?([^\r\n]*)$";
121 value = {
122 to = "https://calibre.clicks.codes/$1";
123 permanent = true;
124 _type = "redirect";
125 headers = null;
126 };
127 }
128 ];
129 authWith = null;
130 enableHttp = false;
131 };
132 };
133 step4 = {
134 "calibre.clicks.codes" = {
135 routes = [
136 {
137 name = "/";
138 value = {
139 host = "generic";
140 port = 1024;
141 protocol = "http";
142 _type = "reverseProxy";
143 headers = {
144 "Access-Control-Allow-Origin" = "*";
145 "X-Clacks-Overhead" = "GNU Terry Pratchett";
146 };
147 };
148 }
149 ];
150 dnsProvider = "cloudflare";
151 authWith = "tailscale";
152 enableHttp = false;
153 };
154 "www.calibre.clicks.codes" = {
155 routes = [
156 {
157 name = "~ ^/?([^\r\n]*)$";
158 value = {
159 to = "https://calibre.clicks.codes/$1";
160 permanent = true;
161 _type = "redirect";
162 headers = null;
163 };
164 }
165 ];
166 authWith = null;
167 enableHttp = false;
168 };
169 };
170 step5 = {
171 "calibre.clicks.codes" = {
172 locations = [
173 {
174 name = "/";
175 value = {
176 proxyPass = "http://generic:1024";
177 proxyWebsockets = true;
178 recommendedProxySettings = true;
179 extraConfig = "\nadd_header \"X-Clacks-Overhead\" \"GNU Terry Pratchett\";\nadd_header \"Access-Control-Allow-Origin\" \"*\";";
180 };
181 }
182 ];
183 dnsProvider = "cloudflare";
184 authWith = "tailscale";
185 enableHttp = false;
186 };
187 "www.calibre.clicks.codes" = {
188 locations = [
189 {
190 name = "~ ^/?([^\r\n]*)$";
191 value = {
192 return = "307 https://calibre.clicks.codes/$1";
193 };
194 }
195 ];
196 authWith = null;
197 enableHttp = false;
198 };
199 };
200 step6 = {
201 "calibre.clicks.codes" = {
202 locations."/" = {
203 priority = 100;
204 proxyPass = "http://generic:1024";
205 proxyWebsockets = true;
206 recommendedProxySettings = true;
207 extraConfig = "\nadd_header \"X-Clacks-Overhead\" \"GNU Terry Pratchett\";\nadd_header \"Access-Control-Allow-Origin\" \"*\";";
208 };
209 dnsProvider = "cloudflare";
210 authWith = "tailscale";
211 enableHttp = false;
212 };
213 "www.calibre.clicks.codes" = {
214 locations."~ ^/?([^\r\n]*)$" = {
215 return = "307 https://calibre.clicks.codes/$1";
216 priority = 100;
217 };
218 authWith = null;
219 enableHttp = false;
220 };
221 };
222 step7 = {
223 "calibre.clicks.codes" = {
224 locations."/" = {
225 priority = 100;
226 proxyPass = "http://generic:1024";
227 proxyWebsockets = true;
228 recommendedProxySettings = true;
229 extraConfig = "\nadd_header \"X-Clacks-Overhead\" \"GNU Terry Pratchett\";\nadd_header \"Access-Control-Allow-Origin\" \"*\";";
230 };
231 onlySSL = true;
232 addSSL = false;
233 useACMEHost = "calibre.clicks.codes";
234 dnsProvider = "cloudflare";
235 authWith = "tailscale";
236 };
237 "www.calibre.clicks.codes" = {
238 locations."~ ^/?([^\r\n]*)$" = {
239 return = "307 https://calibre.clicks.codes/$1";
240 priority = 100;
241 };
242 onlySSL = true;
243 addSSL = false;
244 useACMEHost = "www.calibre.clicks.codes";
245 authWith = null;
246 };
247 };
248in {
249 testGenerateWwwRedirects = {
250 expr = lib.clicks.nginx.http.internal.generateWwwRedirects step0;
251 expected = step1;
252 };
253 testTranslateServiceToRoutes = {
254 expr = lib.clicks.nginx.http.internal.translateServiceToRoutes step1;
255 expected = step2;
256 };
257 testTranslateRoutesDagToList = {
258 expr = lib.clicks.nginx.http.internal.translateRoutesDagToList step2;
259 expected = step3;
260 };
261 testUnwrapHeader = {
262 expr = lib.clicks.nginx.http.internal.unwrapHeaders step3;
263 expected = step4;
264 };
265 testTranslateRoutesToLocations = {
266 expr = lib.clicks.nginx.http.internal.translateRoutesToLocations step4;
267 expected = step5;
268 };
269 testSetLocationPriorities = {
270 expr = lib.clicks.nginx.http.internal.setLocationPriorities step5;
271 expected = step6;
272 };
273 testAddListenDefaults = {
274 expr = lib.clicks.nginx.http.internal.addListenDefaults step6;
275 expected = step7;
276 };
277}