nix-community / vgo2nix

Convert go.mod files to nixpkgs buildGoPackage compatible deps.nix files [maintainer=@adisbladis]
MIT License
90 stars 21 forks source link

Incorrect goPackagePath for subdirectories #11

Closed oxzi closed 5 years ago

oxzi commented 5 years ago

While creating a deps.nix based on a go.mod with a dependency to github.com/ugorji/go/codec, the resulting goPackagePath was incorrect. The problem lies in the subdirectory-like path of this package. Your script parses the full package path (github.com/ugorji/go/codec) correctly and also extracts the correct URL (https://github.com/ugorji/go). However, this results to an entry where the goPackagePath (subdirectory) should fetch its parent folder as source. Therefore the compilation will fail. After changing the goPackagePath to its root (github.com/ugorji/go), everything worked smoothly.

Please excuse my confusing explanation. You can check out this small project of mine, where I came across this issue and modified the one line in deps.nix manually.

Now I'm kind of unsure how to solve this problem.

What are your thoughts about this? I would be happy to fix this, but would love to hear your thoughts first. Thanks for this nice project btw.

adisbladis commented 5 years ago

It turns out we already had this information (it was just discarded). The proper goPackagePath attribute is returned by https://godoc.org/golang.org/x/tools/go/vcs#RepoRootForImportPath.

adisbladis commented 5 years ago

Additionally I have added tests where one of the test cases is based on your report (https://github.com/adisbladis/vgo2nix/tree/master/tests/test_reporoot).

Thanks!

martinetd commented 2 years ago

I've just run into the same problem for https://github.com/ddvk/rmfakecloud

The generated deps.nix (as of master) contains:

  {
    goPackagePath = "github.com/dropbox/dropbox-sdk-go-unofficial/v6";
    fetch = {
      type = "git";
      url = "https://github.com/dropbox/dropbox-sdk-go-unofficial";
      rev = "v6.0.3";
      sha256 = "0wm50livb01i5qjpchknadc443vrpahvzyyn68w69dk4g3i2wcj9";
      moduleDir = "";
    };
  }

But the build fails unless I update goPackagePath to github.com/dropbox/dropbox-sdk-go-unofficial (without /v6 subdir) I honestly have no clue about go however so not sure where you're supposed to guess if we want a subdir or not... I see other sources have a subdir + moduleDir set, but that didn't work in this case.

Here's the error if this helps:

rmfakecloud> go/src/github.com/ddvk/rmfakecloud/internal/integrations/dropbox.go:8:2: cannot find package "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox" in any of:
rmfakecloud>    /nix/store/8jh9rqpmlyvfqmr71hll1a4a7wsqjnja-go-1.17.6/share/go/src/github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox (from $GOROOT)
rmfakecloud>    /build/go/src/github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox (from $GOPATH)
rmfakecloud> go/src/github.com/ddvk/rmfakecloud/internal/integrations/dropbox.go:9:2: cannot find package "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files" in any of:
rmfakecloud>    /nix/store/8jh9rqpmlyvfqmr71hll1a4a7wsqjnja-go-1.17.6/share/go/src/github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files (from $GOROOT)
rmfakecloud>    /build/go/src/github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files (from $GOPATH)

Inspecting manually, there is /build/go/src/github.com/dropbox/dropbox-sdk-go-unofficial/v6/v6/dropbox instead (note two /v6) which made me add a mv in preBuild first, but fixing the deps.nix makes more sense.

(full package here if that helps reproducing, with fixed deps.nix: http://cgit.notk.org/asmadeus/nixos-config.git/tree/pkgs/rmfakecloud/default.nix )

Thanks!