What do you do with GOPATH?

I realized that I had still set GOPATH to a folder in my home directory. Upon removing it my development workflow for go with nix breaks, for obvious reasons, since commands like go mod download can’t write to the nix store.

Does everyone just keep a permanent GOPATH in their shell config? Do you set a GOPATH on a per project basis? Do you handle this completely differently? Note that I’m explicitly not talking about how to build the package for production. It’s just about the development workflow for go.

I just make sure that GOPATH is unset during development… go will fallback to $HOME/go then.

Since the existence of pkgs.go alone in a shell.nix will trigger GOPATH to point into the nix-store, I usually put shellHook = "unset GOPATH" into it. (Thanks for @jonringer telling me about it last week, before that I unset GOPATH manually after entering the shell).

1 Like

I used to put something like this in my shell.nix to set the GOPATH