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.clicks.nginx.http.reverseProxy "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 = "http"; |
| 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 | }; |
| 37 | authWith = null; |
| 38 | service = null; |
| 39 | enableHttp = false; |
| 40 | }; |
| 41 | }; |
| 42 | step2 = { |
| 43 | "calibre.clicks.codes" = { |
| 44 | routes."/" = lib.home-manager.hm.dag.entryAnywhere { |
| 45 | host = "generic"; |
| 46 | port = 1024; |
| 47 | protocol = "http"; |
| 48 | _type = "reverseProxy"; |
| 49 | headers = null; |
| 50 | }; |
| 51 | dnsProvider = "cloudflare"; |
| 52 | authWith = "tailscale"; |
| 53 | enableHttp = false; |
| 54 | }; |
| 55 | "www.calibre.clicks.codes" = { |
| 56 | routes."~ ^/?([^\r\n]*)$" = lib.home-manager.hm.dag.entryAnywhere { |
| 57 | to = "https://calibre.clicks.codes/$1"; |
| 58 | permanent = true; |
| 59 | _type = "redirect"; |
| 60 | headers = null; |
| 61 | }; |
| 62 | authWith = null; |
| 63 | enableHttp = false; |
| 64 | }; |
| 65 | }; |
| 66 | step3 = { |
| 67 | "calibre.clicks.codes" = { |
| 68 | routes = [ |
| 69 | { |
| 70 | name = "/"; |
| 71 | value = { |
| 72 | host = "generic"; |
| 73 | port = 1024; |
| 74 | protocol = "http"; |
| 75 | _type = "reverseProxy"; |
| 76 | headers = null; |
| 77 | }; |
| 78 | } |
| 79 | ]; |
| 80 | dnsProvider = "cloudflare"; |
| 81 | authWith = "tailscale"; |
| 82 | enableHttp = false; |
| 83 | }; |
| 84 | "www.calibre.clicks.codes" = { |
| 85 | routes = [ |
| 86 | { |
| 87 | name = "~ ^/?([^\r\n]*)$"; |
| 88 | value = { |
| 89 | to = "https://calibre.clicks.codes/$1"; |
| 90 | permanent = true; |
| 91 | _type = "redirect"; |
| 92 | headers = null; |
| 93 | }; |
| 94 | } |
| 95 | ]; |
| 96 | authWith = null; |
| 97 | enableHttp = false; |
| 98 | }; |
| 99 | }; |
| 100 | step4 = { |
| 101 | "calibre.clicks.codes" = { |
| 102 | routes = [ |
| 103 | { |
| 104 | name = "/"; |
| 105 | value = { |
| 106 | host = "generic"; |
| 107 | port = 1024; |
| 108 | protocol = "http"; |
| 109 | _type = "reverseProxy"; |
| 110 | headers = null; |
| 111 | }; |
| 112 | } |
| 113 | ]; |
| 114 | dnsProvider = "cloudflare"; |
| 115 | authWith = "tailscale"; |
| 116 | enableHttp = false; |
| 117 | }; |
| 118 | "www.calibre.clicks.codes" = { |
| 119 | routes = [ |
| 120 | { |
| 121 | name = "~ ^/?([^\r\n]*)$"; |
| 122 | value = { |
| 123 | to = "https://calibre.clicks.codes/$1"; |
| 124 | permanent = true; |
| 125 | _type = "redirect"; |
| 126 | headers = null; |
| 127 | }; |
| 128 | } |
| 129 | ]; |
| 130 | authWith = null; |
| 131 | enableHttp = false; |
| 132 | }; |
| 133 | }; |
| 134 | step5 = { |
| 135 | "calibre.clicks.codes" = { |
| 136 | locations = [ |
| 137 | { |
| 138 | name = "/"; |
| 139 | value = { |
| 140 | proxyPass = "http://generic:1024"; |
| 141 | proxyWebsockets = true; |
| 142 | recommendedProxySettings = true; |
| 143 | }; |
| 144 | } |
| 145 | ]; |
| 146 | dnsProvider = "cloudflare"; |
| 147 | authWith = "tailscale"; |
| 148 | enableHttp = false; |
| 149 | }; |
| 150 | "www.calibre.clicks.codes" = { |
| 151 | locations = [ |
| 152 | { |
| 153 | name = "~ ^/?([^\r\n]*)$"; |
| 154 | value = { |
| 155 | return = "307 https://calibre.clicks.codes/$1"; |
| 156 | }; |
| 157 | } |
| 158 | ]; |
| 159 | authWith = null; |
| 160 | enableHttp = false; |
| 161 | }; |
| 162 | }; |
| 163 | step6 = { |
| 164 | "calibre.clicks.codes" = { |
| 165 | locations."/" = { |
| 166 | priority = 100; |
| 167 | proxyPass = "http://generic:1024"; |
| 168 | proxyWebsockets = true; |
| 169 | recommendedProxySettings = true; |
| 170 | }; |
| 171 | dnsProvider = "cloudflare"; |
| 172 | authWith = "tailscale"; |
| 173 | enableHttp = false; |
| 174 | }; |
| 175 | "www.calibre.clicks.codes" = { |
| 176 | locations."~ ^/?([^\r\n]*)$" = { |
| 177 | return = "307 https://calibre.clicks.codes/$1"; |
| 178 | priority = 100; |
| 179 | }; |
| 180 | authWith = null; |
| 181 | enableHttp = false; |
| 182 | }; |
| 183 | }; |
| 184 | step7 = { |
| 185 | "calibre.clicks.codes" = { |
| 186 | locations."/" = { |
| 187 | priority = 100; |
| 188 | proxyPass = "http://generic:1024"; |
| 189 | proxyWebsockets = true; |
| 190 | recommendedProxySettings = true; |
| 191 | }; |
| 192 | onlySSL = true; |
| 193 | addSSL = false; |
| 194 | useACMEHost = "calibre.clicks.codes"; |
| 195 | dnsProvider = "cloudflare"; |
| 196 | authWith = "tailscale"; |
| 197 | }; |
| 198 | "www.calibre.clicks.codes" = { |
| 199 | locations."~ ^/?([^\r\n]*)$" = { |
| 200 | return = "307 https://calibre.clicks.codes/$1"; |
| 201 | priority = 100; |
| 202 | }; |
| 203 | onlySSL = true; |
| 204 | addSSL = false; |
| 205 | useACMEHost = "www.calibre.clicks.codes"; |
| 206 | authWith = null; |
| 207 | }; |
| 208 | }; |
| 209 | in { |
| 210 | testGenerateWwwRedirects = { |
| 211 | expr = lib.clicks.nginx.http.internal.generateWwwRedirects step0; |
| 212 | expected = step1; |
| 213 | }; |
| 214 | testTranslateServiceToRoutes = { |
| 215 | expr = lib.clicks.nginx.http.internal.translateServiceToRoutes step1; |
| 216 | expected = step2; |
| 217 | }; |
| 218 | testTranslateRoutesDagToList = { |
| 219 | expr = lib.clicks.nginx.http.internal.translateRoutesDagToList step2; |
| 220 | expected = step3; |
| 221 | }; |
| 222 | testUnwrapHeaderPassthrough = { |
| 223 | expr = lib.clicks.nginx.http.internal.unwrapHeaders step3; |
| 224 | expected = step4; |
| 225 | }; |
| 226 | testTranslateRoutesToLocations = { |
| 227 | expr = lib.clicks.nginx.http.internal.translateRoutesToLocations step4; |
| 228 | expected = step5; |
| 229 | }; |
| 230 | testSetLocationPriorities = { |
| 231 | expr = lib.clicks.nginx.http.internal.setLocationPriorities step5; |
| 232 | expected = step6; |
| 233 | }; |
| 234 | testAddListenDefaults = { |
| 235 | expr = lib.clicks.nginx.http.internal.addListenDefaults step6; |
| 236 | expected = step7; |
| 237 | }; |
| 238 | } |