Go on Nix? Upgrading gomod2nix?

G’day,

I hope everyone is doing well.

Quick update
I’ve done some comparison testing.

Today, I setup a little repo with a small go program, and compared the speed and size of building the code into a container in various ways.

Summary is here, with detailed output in the readme.md also

In theory, you could git clone this and do “make” and it will build them all for you also. Hopefully your results don’t differ much.

Summary
Maybe I have something wrong with gomod2nix, because it’s not faster, and the container image is a lot larger. I suspect it’s larger because it has pulled in a lot more glibc stuffs, but I clearly need to debug this to bring the size down.

I had been expecting gomod2nix to be a lot faster when making a small change to the cmd/go_nix_simple/go_nix_simple.go, because it could reuse the nix cache for the github.com/prometheus/client_golang/prometheus modules. Maybe I’ve stuffed up the gomod2nix implementation?

Maybe this isn’t a great test, because there aren’t very many modules, and I’m not building a whole bunch of go code, which would get better nix reuse between programs.

Not entirely Nix related
I’ve recently discovered the docker caching, which is really great. If anyone is building go within docker containers, I strongly recommend doing this. The docker cache make building go really fast!

Today I also tried out Athens GOPROXY caching which is also pretty good . I’m definitely planning to add Athens caching to our k8s clusters now. However, after banging my head for a while, I couldn’t get nix build to use the GO_PROXY, which is annoying. It turns out this is apparently deliberate, although I’m not sure I really understand why ( I’m clearly missing something ).

    configurePhase = args.configurePhase or (''
      runHook preConfigure

      export GOCACHE=$TMPDIR/go-cache
      export GOPATH="$TMPDIR/go"
      export GOPROXY=off                        <---- DISABLED
      export GOSUMDB=off                              <---- Not sure why they do this.  Scary!

It sort of looks like you might be able to set a impureEnvVars GOPROXY, but I couldn’t get this to work. :frowning:

I also found this related discourse thread, but again, I’m not clear how go being about to pull from a GO_PROXY is really a problem. go.sum is supposed to catch any shenanigans.

Thanks in advance,
Dave