My understanding is that Bazel just re-implements whatever the Go tool does. It’s not that different from compiling/linking C. A Nix-aware Go build tool could do the same. I just wonder who has the incentive to maintain something like that.
After thinking about this thread on and off for a while, I had a crazy idea for how to do this the right way with fine-grained derivations for Go, and I finally got it working (on small examples at least).
First, the code: GitHub - dnr/dgd: Dynamic Go Derivations — fine-grained Go builds for Nix
The “crazy idea” is to parse the output of go build -n (the “dry-run” that just outputs a list of shell commands) and process it into tiny derivations. Then you can either use them as dynamic derivations or with IFD. There’s a few more tricks to break up dependencies and sources into smaller pieces for better caching.
This is Go-specific, of course, and also it’s kind of slow. I was getting 1.5× slower than a cold-cache Go build on a small-ish project, which isn’t really that bad considering what’s going on. Incremental builds were pretty fast but had a minimum of a couple seconds.
I don’t expect anyone to use this right now (though let me know if you try it!), but maybe it’s a small step on a path towards fast dynamic derivations for everything.
Consider joining the dream2nix folks with this; they’re doing similar things for JS, PHP and Rust so far.