Persist and share GOCACHE

go has some pretty aggressive, immutable build caching that really helps speed up builds. I could be wrong, but this seems to be largely ignored, since we export GOCACHE=$TMPDIR/go-cache. this is an understandable pragmatic decision, since the cache MUST be writable and should not really be part of the output.

that said, it would be quite cool to be able to hoist these entries into /nix/store as part of some go cache abstraction that can be picked up by the likes of buildGoXxx. there are some massive missing implementation details for sure, but I could conceive of making them intermediate derivations like source, that way they are not fetched automatically, get garbage collected after time has passed, but still get shared between go module builds.

has this been attempted for any other languages, is there context I am missing, anything else?

Yes, for example with node2nix or crane but that leads to massive build slowdowns because building 2 derivations is always faster than potential hundreds.

Also there is GitHub - nix-community/gomod2nix: Convert applications using Go modules to Nix expressions [maintainer=@adisbladis] which I consider an uphill battle due to inflexibility of go mod.