Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: buildGoModule Support #51

Open
diogox opened this issue Jan 14, 2022 · 7 comments
Open

Feature Request: buildGoModule Support #51

diogox opened this issue Jan 14, 2022 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@diogox
Copy link

diogox commented Jan 14, 2022

Hi 馃憢

buildGoModule requires a vendorSha256 field to be built. I was wondering if this could be supported by nvfetcher like it is for Rust?

Thanks!

@berberman
Copy link
Owner

berberman commented Jan 14, 2022

The vendorSha256 in buildGoModule is output hash of an intermediate drv, and it seems that there's no way to calculate it before actually building the package: https://discourse.nixos.org/t/buildgomodule-how-to-get-vendorsha256/9317. This is different from the situation of rust packages -- everything can be calculated from Cargo.lock without building the drv.

@berberman berberman added enhancement New feature or request help wanted Extra attention is needed labels Jan 14, 2022
@diogox
Copy link
Author

diogox commented Jan 17, 2022

I'm not familiar with this project's code, but can't we run this nix-prefetch to get the vendorSha256?

nix-prefetch '{ sha256 }: golangci-lint.go-modules.overrideAttrs (_: { modSha256 = sha256; })'

Where golangci-lint is the name of the package? Of course this would not work for local packages as it stands 馃

@berberman
Copy link
Owner

but can't we run this nix-prefetch to get the vendorSha256?

No, because nvfetcher runs before we have the derivation, whereas using nix-prefetch like that requires the derivation.

@NickCao
Copy link
Sponsor Contributor

NickCao commented Feb 2, 2022

vendorSha256 can be computed (or built) from go.sum alone, just like with Cargo.lock, however the process is harder due the the obscure tree hashing scheme of go modules. A somehow working example can be found here: https://gist.github.com/NickCao/e2135fae47b31798c5d03cae1d242cb3

@NickCao
Copy link
Sponsor Contributor

NickCao commented Feb 2, 2022

To make the situation worse, go.sum generated by go pre 1.16 and go 1.17 differs slightly and is generally incompatible.

TLATER added a commit to TLATER/dotfiles that referenced this issue Feb 28, 2022
See berberman/nvfetcher#51 for why this is required.
@NickCao
Copy link
Sponsor Contributor

NickCao commented Apr 17, 2022

With the introduction of impure derivations in recent versions of nix, the approach in https://gist.github.com/NickCao/e2135fae47b31798c5d03cae1d242cb3 is now feasible (without considering pouring tens of thousands of derivations into your nix store).

@bandithedoge
Copy link

In some cases you can pass null to vendorSha256 to use vendored dependencies from your source repo. There is also the legacy buildGoPackage, which requires goDeps generated with go2nix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants