blob: 801230cf97a9f0f5b9dc6b0f87345965c6c29267 [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.clicks.nginx.http.reverseProxySecure "generic" 1024;
9 www = true;
10 dnsProvider = "cloudflare";
11 routes = null;
12 authWith = "tailscale";
13 enableHttp = false;
14 };
15 };
16 step1 = {
17 "calibre.clicks.codes" = {
18 service = {
19 host = "generic";
20 port = 1024;
21 protocol = "https";
22 _type = "reverseProxy";
23 headers = null;
24 };
25 dnsProvider = "cloudflare";
26 routes = null;
27 authWith = "tailscale";
28 enableHttp = false;
29 };
30 "www.calibre.clicks.codes" = {
31 routes."~ ^/?([^\r\n]*)$" = lib.home-manager.hm.dag.entryAnywhere {
32 to = "https://calibre.clicks.codes/$1";
33 permanent = true;
34 _type = "redirect";
35 headers = null;
36 };
Skyler Grey13068952024-08-20 22:56:49 +000037 dnsProvider = "cloudflare";
Skyler Greyd7e1acd2024-06-22 14:42:11 +000038 authWith = null;
39 service = null;
40 enableHttp = false;
41 };
42 };
43 step2 = {
44 "calibre.clicks.codes" = {
45 routes."/" = lib.home-manager.hm.dag.entryAnywhere {
46 host = "generic";
47 port = 1024;
48 protocol = "https";
49 _type = "reverseProxy";
50 headers = null;
51 };
52 dnsProvider = "cloudflare";
53 authWith = "tailscale";
54 enableHttp = false;
55 };
56 "www.calibre.clicks.codes" = {
57 routes."~ ^/?([^\r\n]*)$" = lib.home-manager.hm.dag.entryAnywhere {
58 to = "https://calibre.clicks.codes/$1";
59 permanent = true;
60 _type = "redirect";
61 headers = null;
62 };
Skyler Grey13068952024-08-20 22:56:49 +000063 dnsProvider = "cloudflare";
Skyler Greyd7e1acd2024-06-22 14:42:11 +000064 authWith = null;
65 enableHttp = false;
66 };
67 };
68 step3 = {
69 "calibre.clicks.codes" = {
70 routes = [
71 {
72 name = "/";
73 value = {
74 host = "generic";
75 port = 1024;
76 protocol = "https";
77 _type = "reverseProxy";
78 headers = null;
79 };
80 }
81 ];
82 dnsProvider = "cloudflare";
83 authWith = "tailscale";
84 enableHttp = false;
85 };
86 "www.calibre.clicks.codes" = {
87 routes = [
88 {
89 name = "~ ^/?([^\r\n]*)$";
90 value = {
91 to = "https://calibre.clicks.codes/$1";
92 permanent = true;
93 _type = "redirect";
94 headers = null;
95 };
96 }
97 ];
Skyler Grey13068952024-08-20 22:56:49 +000098 dnsProvider = "cloudflare";
Skyler Greyd7e1acd2024-06-22 14:42:11 +000099 authWith = null;
100 enableHttp = false;
101 };
102 };
103 step4 = {
104 "calibre.clicks.codes" = {
105 routes = [
106 {
107 name = "/";
108 value = {
109 host = "generic";
110 port = 1024;
111 protocol = "https";
112 _type = "reverseProxy";
113 headers = null;
114 };
115 }
116 ];
117 dnsProvider = "cloudflare";
118 authWith = "tailscale";
119 enableHttp = false;
120 };
121 "www.calibre.clicks.codes" = {
122 routes = [
123 {
124 name = "~ ^/?([^\r\n]*)$";
125 value = {
126 to = "https://calibre.clicks.codes/$1";
127 permanent = true;
128 _type = "redirect";
129 headers = null;
130 };
131 }
132 ];
Skyler Grey13068952024-08-20 22:56:49 +0000133 dnsProvider = "cloudflare";
Skyler Greyd7e1acd2024-06-22 14:42:11 +0000134 authWith = null;
135 enableHttp = false;
136 };
137 };
138 step5 = {
139 "calibre.clicks.codes" = {
140 locations = [
141 {
142 name = "/";
143 value = {
144 proxyPass = "https://generic:1024";
145 proxyWebsockets = true;
146 recommendedProxySettings = true;
147 };
148 }
149 ];
150 dnsProvider = "cloudflare";
151 authWith = "tailscale";
152 enableHttp = false;
153 };
154 "www.calibre.clicks.codes" = {
155 locations = [
156 {
157 name = "~ ^/?([^\r\n]*)$";
158 value = {
159 return = "307 https://calibre.clicks.codes/$1";
160 };
161 }
162 ];
Skyler Grey13068952024-08-20 22:56:49 +0000163 dnsProvider = "cloudflare";
Skyler Greyd7e1acd2024-06-22 14:42:11 +0000164 authWith = null;
165 enableHttp = false;
166 };
167 };
168 step6 = {
169 "calibre.clicks.codes" = {
170 locations."/" = {
171 priority = 100;
172 proxyPass = "https://generic:1024";
173 proxyWebsockets = true;
174 recommendedProxySettings = true;
175 };
176 dnsProvider = "cloudflare";
177 authWith = "tailscale";
178 enableHttp = false;
179 };
180 "www.calibre.clicks.codes" = {
181 locations."~ ^/?([^\r\n]*)$" = {
182 return = "307 https://calibre.clicks.codes/$1";
183 priority = 100;
184 };
Skyler Grey13068952024-08-20 22:56:49 +0000185 dnsProvider = "cloudflare";
Skyler Greyd7e1acd2024-06-22 14:42:11 +0000186 authWith = null;
187 enableHttp = false;
188 };
189 };
190 step7 = {
191 "calibre.clicks.codes" = {
192 locations."/" = {
193 priority = 100;
194 proxyPass = "https://generic:1024";
195 proxyWebsockets = true;
196 recommendedProxySettings = true;
197 };
198 onlySSL = true;
199 addSSL = false;
200 useACMEHost = "calibre.clicks.codes";
201 dnsProvider = "cloudflare";
202 authWith = "tailscale";
203 };
204 "www.calibre.clicks.codes" = {
205 locations."~ ^/?([^\r\n]*)$" = {
206 return = "307 https://calibre.clicks.codes/$1";
207 priority = 100;
208 };
Skyler Grey13068952024-08-20 22:56:49 +0000209 dnsProvider = "cloudflare";
Skyler Greyd7e1acd2024-06-22 14:42:11 +0000210 onlySSL = true;
211 addSSL = false;
212 useACMEHost = "www.calibre.clicks.codes";
213 authWith = null;
214 };
215 };
216in {
217 testGenerateWwwRedirects = {
218 expr = lib.clicks.nginx.http.internal.generateWwwRedirects step0;
219 expected = step1;
220 };
221 testTranslateServiceToRoutes = {
222 expr = lib.clicks.nginx.http.internal.translateServiceToRoutes step1;
223 expected = step2;
224 };
225 testTranslateRoutesDagToList = {
226 expr = lib.clicks.nginx.http.internal.translateRoutesDagToList step2;
227 expected = step3;
228 };
229 testUnwrapHeaderPassthrough = {
230 expr = lib.clicks.nginx.http.internal.unwrapHeaders step3;
231 expected = step4;
232 };
233 testTranslateRoutesToLocations = {
234 expr = lib.clicks.nginx.http.internal.translateRoutesToLocations step4;
235 expected = step5;
236 };
237 testSetLocationPriorities = {
238 expr = lib.clicks.nginx.http.internal.setLocationPriorities step5;
239 expected = step6;
240 };
241 testAddListenDefaults = {
242 expr = lib.clicks.nginx.http.internal.addListenDefaults step6;
243 expected = step7;
244 };
245}