Search code examples
gounixnix

NIX - go: modules disabled by GO111MODULE=off;


I'm trying to download and build a project written in golang using nix

My nix file:

buildGoPackage {      
  name = "site";     
  goPackagePath = "git@github.com:username/rep.git";    
  src = fetchGit{      
       url = "git@github.com:username/rep.git";     
  }; 
}

run:

nix build -f test3.nix

error log:

last 8 log lines:        
 > unpacking sources       
 > unpacking source archive /nix/store/l1gsllgg693s46sk7b7qiwbnjysnbbz6-source        
 > source root is source        
 > patching sources        
 > configuring       
 > building        
 > Building subPackage git@github.com:user/rep.git        
 > go: modules disabled by GO111MODULE=off; see 'go help modules'

Solution

  • I think you should be using buildGoModule instead of buildGoPackage, as buildGoPackage is deprecated, according to the nixpkgs documentation for go.

    Additionally, buildGoModule doesn't seem to set GO111MODULE=off.