Search code examples
nix

Set environment parameter in Nix for a building phase for buildGoModule?


I am trying to build a Go moodule with buildGoModule. My issue is that during building time go tries to reach out to proxy.golang.org but it is block in my network and solution is to set an environment variable GOPROXY.

I thought that passthru = { GOPROXY = "direct"; }; would do the job, but the error persists. So I would like to know what is a good way to pass an env variable.

Overriding GOPROXY should work since I tested it in nix-shell separately - it works fine.


Solution

  • In buildGoModule it is possible to override go-modules derivation with overrideModAttrs.

    Specifically for GOPROXY it would look like:

    overrideModAttrs = (_: {
      GOPROXY = "whatever";
    });