How can I find the value of vendorSha256?

I’m trying to understand how vendorSha256 is being generated.

For example, let’s assume I want to write this nix expression from scratch:

{ lib, buildGoModule, fetchFromGitHub }:

buildGoModule rec {
  pname = "oapi-codegen";
  version = "1.6.0";

  src = fetchFromGitHub {
    owner = "deepmap";
    repo = pname;
    rev = "v${version}";
    sha256 = "sha256-doJ1ceuJ/gL9vlGgV/hKIJeAErAseH0dtHKJX2z7pV0=";

  vendorSha256 = "sha256-Y4WM+o+5jiwj8/99UyNHLpBNbtJkKteIGW2P1Jd9L6M=";

  # Tests use network
  doCheck = false;

  meta = with lib; {
    description = "Go client and server OpenAPI 3 generator";
    homepage    = "";
    license     = licenses.asl20;
    maintainers = [ maintainers.j4m3s ];

I managed to find sha256 value by downloading the source from github, unzip it, and then ran on the extracted oapi-codegen-1.6.0 directory:

nix hash path --base64 --type sha256 oapi-codegen-1.6.0

But I couldn’t find how to get the value of vendorSha256. From nixpkgs manual I get this info:

  • vendorSha256 : is the hash of the output of the intermediate fetcher derivation. vendorSha256 can also take null as an input. When null is used as a value, rather than fetching the dependencies and vendoring them, we use the vendoring included within the source repo. If you’d like to not have to update this field on dependency changes, run go mod vendor in your source repo and set vendorSha256 = null;

When I run:

nix-build -E 'with import <nixpkgs> { }; callPackage ./myCustomExpression.nix { }'

I see the first lines of output as:

these 2 derivations will be built:

So I guess the intermediate fetcher derivation is j13s3dvlwz5w9xl5wbhkcs7lrkgksv3l-oapi-codegen-1.6.0-go-modules.drv. This derivation will be used to fetch all of the dependencies of the Go module as I read in the manual.

But how can I know the hash of this itermediate fetcher derivation if at the time I’m writing my Nix expression I haven’t built it yet? There must be a way since the guys contributing to nixpkgs know how to add it, but I cannot manage to figure it out.

Thanks in advance!

Use lib.fakeHash as initial value, build, take the one from error, rebuild.


It’s a hack, but I just change a single character to invalidate it, then let nix tell me what it expected.

The other option would be doing something like nix-build -A oapi-codegen.go-modules --rebuild, where you build the derivation even if there’s already a realized store path.

1 Like
Hosted by Flying Circus.