buildGoModule building submodule

Hello!

i’m trying to build go binary.

package with binary itself has go.mod

expression

{ stdenv, buildGoModule, fetchFromGitHub, fetchhg, fetchbzr, fetchsvn, lib }:

buildGoModule rec {
  name = "grpc-unstable-${version}";
  version = "1.31.1";

  vendorSha256 = "1d3kq38d20cd30px471c47zi1vgl9vw8ihnfg7fpqz923vbkzlvc";#lib.fakeSha256;

  subPackages = [ "cmd/protoc-gen-go-grpc" ];

  src = fetchFromGitHub {
    owner = "grpc";
    repo = "grpc-go";
    rev = "v${version}";
    sha256 = "18565vf9i2zc69znd9b8a2iz0kgv5cms0g0ppj93hnhri8rjqagk";
  };
}

but when i invoke

nix-shell -p go-protoc-gen-go-grpc

i got

these derivations will be built:
  /nix/store/fcmxp5579fxp2ksbrljh59l423hp4nh3-grpc-unstable-1.31.1.drv
building '/nix/store/fcmxp5579fxp2ksbrljh59l423hp4nh3-grpc-unstable-1.31.1.drv'...
unpacking sources
unpacking source archive /nix/store/17r5czpky3djlbqhjcmxikvcq5lkd7im-source
source root is source
patching sources
configuring
building
Building subPackage ./cmd/protoc-gen-go-grpc
main module (google.golang.org/grpc) does not contain package google.golang.org/grpc/cmd/protoc-gen-go-grpc
builder for '/nix/store/fcmxp5579fxp2ksbrljh59l423hp4nh3-grpc-unstable-1.31.1.drv' failed with exit code 1
error: build of '/nix/store/fcmxp5579fxp2ksbrljh59l423hp4nh3-grpc-unstable-1.31.1.drv' failed

whats going wrong?

I ran into this as well. While I’m not sure what’s going on, I noticed using buildGoPackage rather than buildGoModule seems to work. Since it seems they both have their advantages, just using buildGoPackage seems reasonable here.

I proposed grpc-go for inclusion in nixpkgs

I since learned that this also works with buildGoModule when you use modRoot instead of subPackages.