gomod2nix
gomod2nix copied to clipboard
Cannot find package "." in
Describe the bug gomod2nix seems to struggle with go dependencies that are part of the repo and referenced by relative paths. When I try and package regen-network I am getting this error:
app/app.go:10:2: cannot find package "." in:
/build/source/vendor/github.com/regen-network/regen-ledger/types/module
app/app.go:95:2: cannot find package "." in:
/build/source/vendor/github.com/regen-network/regen-ledger/types/module/server
app/app.go:96:2: cannot find package "." in:
/build/source/vendor/github.com/regen-network/regen-ledger/x/ecocredit
app/app.go:11:2: cannot find package "." in:
/build/source/vendor/github.com/regen-network/regen-ledger/x/ecocredit/module
The issue seems to be with these dependencies. The relevant error sites are listed below:
- https://github.com/regen-network/regen-ledger/blob/master/app/app.go#L10-L11
- https://github.com/regen-network/regen-ledger/blob/master/app/app.go#L95-L96
I also think that this has something to do with the local replace directives here
To Reproduce
I created a repro repo here. You should just have to run nix build to get the error. Since the repo is a flake you can just run nix build github:JonathanLorimer/gomod-repro-1 without even cloning the repo.
Expected behavior I expected this module to build without errors
Environment
- OS name + version:
NixOS 21.11 (Porcupine) x86_64 - Version of the code:
67f22dd738d092c6ba88e420350ada0ed4992ae8
Additional context I have very limited golang knowledge so there might be something completely wrong with the go side of things and I am just missing it. Thank you for your help in advance!
Getting this issue resolved will help me close https://github.com/informalsystems/cosmos.nix/issues/19
Okay, I think I have identified what the issue is! These local, relative path, directives don't end up in the go.sum. This means that gomod2nix doesn't end up picking them up and they are missing from the vendor-env! I am not sure what the best solution to this is, right now I am trying to figure out a hacky work around to just splice in the dependency I need.
Have similar issue with packaging dasel.
Similar issue (Cannot find package "." in) when packaging https://github.com/mickael-menu/zk.
The customVendorSrc (#22) there would be https://github.com/aymerick/raymond/.
Adding nix-casync to the affected go software.
This issue is not fully resolved but was auto-closed by Github when #41 was merged.
@JonathanLorimer Have you solved this issue for yourself? I got this too with Zitadel. Trying to use your PR as a flake input resulted in some errors.
This might be a different issue though? (There are not really local packages...)
../protoc-base/templates.go:9:2: cannot find package "." in:
/build/source/gopath/src/github.com/zitadel/zitadel/vendor/github.com/Masterminds/sprig
../protoc-base/protoc_helper.go:12:2: cannot find package "." in:
/build/source/gopath/src/github.com/zitadel/zitadel/vendor/github.com/golang/glog
../protoc-base/protoc_helper.go:13:2: cannot find package "." in:
/build/source/gopath/src/github.com/zitadel/zitadel/vendor/github.com/golang/protobuf/proto
../protoc-base/protoc_helper.go:14:2: cannot find package "." in:
/build/source/gopath/src/github.com/zitadel/zitadel/vendor/github.com/golang/protobuf/protoc-gen-go/plugin
../protoc-base/protoc_helper.go:15:2: cannot find package "." in:
/build/source/gopath/src/github.com/zitadel/zitadel/vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor
../protoc-base/templates.go:12:2: cannot find package "." in:
/build/source/gopath/src/github.com/zitadel/zitadel/vendor/golang.org/x/tools/imports
authoption/options.pb.go:10:2: cannot find package "." in:
/build/source/gopath/src/github.com/zitadel/zitadel/vendor/google.golang.org/protobuf/reflect/protoreflect
authoption/options.pb.go:11:2: cannot find package "." in:
/build/source/gopath/src/github.com/zitadel/zitadel/vendor/google.golang.org/protobuf/runtime/protoimpl
authoption/options.pb.go:12:2: cannot find package "." in:
/build/source/gopath/src/github.com/zitadel/zitadel/vendor/google.golang.org/protobuf/types/descriptorpb
I do override buildPhase, could that be the problem?
Actually, this is still in the configurePhase, as I need to generate some go files there. Irrelevant to this issue then.
Any fixes or workarounds for this?
I just ran into this same issue. Are there any fixes or workarounds for this?
^ I have the same issue, here's a minimal repro. What is the current status of this repository -- is it maintained?
@peterldowns - I hit a very similar issue at the same opentelemetry module.
@nix { "action": "setPhase", "phase": "buildPhase" }
building
Building subPackage .
go: finding module for package go.opentelemetry.io/otel/exporters/otlp/internal
vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/exporter.go:22:2: cannot query module due to -mod=vendor
Internally the buildPhase seems to call go install -mod=vendor . but then tries to query for the module in the otel/exporter.go imports. Go install does not seem to allow this with the mod=vendor (this is the error).
Maybe go install tries to fetch the module because it can't find it in the vendored modules in a similar way that it cannot find package "." ?
@ezdac hmm, I'm not sure. I was not able to find a fix for this problem and I worked around it by removing opentelemetry as a dependency from my project (it wasn't necessary, thankfully). It doesn't seem like anyone is working on this issue and I myself am not inclined to. You may consider putting up an easy way to reproduce the failure you're receiving, similar to what I did, to help the maintainers out if in the future they decide to try to fix this.
fwiw I just switched to using buildGoMod119 from nixpkgs, example here. Might be worth it if you have to depend on a package that breaks gomod2nix.
I believe this issue is caused by the weird module structure of go.opentelemetry.io/otel/exporters. I changed populateVendorPath to be recursive as hinted by the TODO which fixed the issue in my case.
Here is some logs indicating that it had to go three directories deep to create the missing symlinks:
vendor-env> symlink error, trying /nix/store/93w4h87w5hd0sz90mx8bcbd539v58y56-otel_v1.16.0/exporters symlink /nix/store/93w4h87w5hd0sz90mx8bcbd539v58y56-otel_v1.16.0/exporters vendor/go.opentelemetry.io/otel/exporters: file exists
vendor-env> symlink error, trying /nix/store/93w4h87w5hd0sz90mx8bcbd539v58y56-otel_v1.16.0/exporters/otlp symlink /nix/store/93w4h87w5hd0sz90mx8bcbd539v58y56-otel_v1.16.0/exporters/otlp vendor/go.opentelemetry.io/otel/exporters/otlp: file exists
vendor-env> symlink error, trying /nix/store/93w4h87w5hd0sz90mx8bcbd539v58y56-otel_v1.16.0/exporters/otlp/internal symlink /nix/store/93w4h87w5hd0sz90mx8bcbd539v58y56-otel_v1.16.0/exporters/otlp/internal vendor/go.opentelemetry.io/otel/exporters/otlp/internal: file exists