Home

infra @d90c04166f06de839690278fa032be27d0d3e86a - refs - log -
-
https://git.jolheiser.com/infra.git
dragonwell flake
infra / dragonwell / services / go.nix
- raw -
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{ jolheiser, lib, ... }:
let
  enable = true;
  altModules = [
    {
      name = "hcaptcha";
      repo = "gitea.com/jolheiser/hcaptcha";
    }
    {
      name = "pwn";
      repo = "gitea.com/jolheiser/pwn";
    }
  ];
  host = "go.${jolheiser.domain}";
  redirects = builtins.concatStringsSep "\n" (
    builtins.map (module: ''
      respond /${module.name}* `<html><head>
                <meta name="go-import" content="${host}/${module.name} git https://${module.repo}.git">
                <meta http-equiv="refresh" content="3; url=https://pkg.go.dev/${host}/${module.name}" />
                </head><body>
                Redirecting to <a href="https://pkg.go.dev/${host}/${module.name}">https://pkg.go.dev/${host}/${module.name}</a>
                </body></html>`
    '') altModules
  );
in
lib.mkIf enable {
  services.caddy.virtualHosts."${host}" = {
    extraConfig = ''
      header Content-Type text/html
      ${redirects}
      respond /* `<html><head>
        <meta name="go-import" content="${host}{path} git https://git.jolheiser.com{path}.git">
        <meta http-equiv="refresh" content="3; url=https://pkg.go.dev/${host}{path}" />
        </head><body>
        Redirecting to <a href="https://pkg.go.dev/${host}{path}">https://pkg.go.dev/${host}{path}</a>
        </body></html>`
    '';
  };
}