about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-09-10T10·40+0200
committerclbot <clbot@tvl.fyi>2023-09-10T11·43+0000
commit9786255267671f5a8f1ed856d938283139ccf41d (patch)
treee38724dab4c3fb757ba2385b67a9ad43f16cbd8b
parent6fa80ecc3def2145b4af0c292ffc0d1b82df3030 (diff)
feat(ops/modules/code.tvl.fyi): fix go get for tvix store protos r/6575
There's a go.mod in in tvix/store/protos, which sets the module path to
code.tvl.fyi/tvix/store/protos.

While this path makes kinda sense, it's currently not possible to `go
get` it from that location, as we serve the cgit interface from there.

Fortunately, `go get` has a mechanism to determine clone URLs for a
given go module path, as documented in https://go.dev/ref/mod#vcs-find.

We simply need to serve a small HTML file at that path, describing the
proper clone URL.

This points the clone URL for code.tvl.fyi/tvix/store/protos to a josh-
provided subtree of just :/tvix/store/protos, which will contain the
root go.mod file.

We need another layer of indirection as nginx can't have an `alias`
directive inside a conditional block (but can have a redirect).

Contrary to https://b.tvl.fyi/issues/299#comment-464, it seems to work
for our usecase. It might become a problem if we actually serve `go.mod`
files in a nested fashion at some point, but let's look at that once we
get there.

Fixes b/299.

Change-Id: Idcad795105af5d57e6d06de6e232881dccf9110b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9290
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: adisbladis <adisbladis@gmail.com>
Reviewed-by: tazjin <tazjin@tvl.su>
-rw-r--r--ops/modules/www/code.tvl.fyi.nix12
1 files changed, 11 insertions, 1 deletions
diff --git a/ops/modules/www/code.tvl.fyi.nix b/ops/modules/www/code.tvl.fyi.nix
index 3f34a9422cb1..5a7a9193ae13 100644
--- a/ops/modules/www/code.tvl.fyi.nix
+++ b/ops/modules/www/code.tvl.fyi.nix
@@ -1,4 +1,4 @@
-{ depot, config, ... }:
+{ depot, pkgs, config, ... }:
 
 {
   imports = [
@@ -20,6 +20,16 @@
             alias ${depot.tvix.docs.svg}/component-flow.svg;
         }
 
+        location = /go-get/tvix/store/protos {
+            alias ${pkgs.writeText "go-import-metadata.html" ''<html><meta name="go-import" content="code.tvl.fyi/tvix/store/protos git https://code.tvl.fyi/depot.git:/tvix/store/protos.git"></html>''};
+        }
+
+        location = /tvix/store/protos {
+            if ($args ~* "/?go-get=1") {
+                return 302 /go-get/tvix/store/protos;
+            }
+        }
+
         # Git operations on depot.git hit josh
         location /depot.git {
             proxy_pass http://localhost:${toString config.services.depot.josh.port};