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