Inconsistent hash of buildGoModule

I’m trying to package terraform-godaddy to use in one of my projects.

However the build either fails locally or on the CI pipeline, each
expecting a different hash for modSha256. When running locally, it
tries to build but complains with:

hash mismatch in fixed-output derivation '/nix/store/jgbfkhlsz6bmq724p5cqqcgfyc7l6sdv-terraform-godaddy-1.6.4-go-modules':
  wanted: sha256:0p81wqw2n8vraxk20xwg717582ijwq2k7v5j3n13y4cd5bxd8hhz
  got:    sha256:10n2dy7q9kk1ly58sw965n6qa8l0nffh8vyd1vslx0gdlyj25xxs
cannot build derivation '/nix/store/y5961vv6y9c0ps2sbd8xfnpqvk0q7qhq-terraform-godaddy-1.6.4.drv': 1 dependencies couldn't be built

If I change the hash to the one it got the build passes locally, but
fails on the CI with the inverse:

hash mismatch in fixed-output derivation '/nix/store/q8y0mzjl78hfhazjgq2sc84i7dp9wnh0-terraform-godaddy-1.6.4-go-modules':
  wanted: sha256:10n2dy7q9kk1ly58sw965n6qa8l0nffh8vyd1vslx0gdlyj25xxs
  got:    sha256:0p81wqw2n8vraxk20xwg717582ijwq2k7v5j3n13y4cd5bxd8hhz
cannot build derivation '/nix/store/w4ghinrmpq524k3617ikfc8i42aa0dbb-terraform-godaddy-1.6.4.drv': 1 dependencies couldn't be built

The offending derivation is:

terraform-godaddy = pkgs.buildGoModule rec {
  name = "terraform-godaddy-${version}";
  version = "1.6.4";
  src = pkgs.fetchFromGitHub {
    owner = "n3integration";
    repo = "terraform-godaddy";
    rev = "v${version}";
    sha256 = "00blqsan74s53dk9ab4hxi1kzxi46k57dr65dmbiradfa3yz3852";
  };
  modSha256 = "0p81wqw2n8vraxk20xwg717582ijwq2k7v5j3n13y4cd5bxd8hhz";
  postInstall =
  "mv $out/bin/terraform-godaddy $out/bin/terraform-provider-godaddy";
};

Why is it changing? Where this difference might be coming from?

I tried looking at the Go modules section of the manual, but there
was nothing special regarding Go that would differ from any normal
derivation.

I couldn’t find anything online too. The full log of the local and CI
builds is also available.

Do they both reference the same nixpkgs? seems like you’re using ‘’ in https://git.sr.ht/~euandreh/vps/tree/6ba76140238b5e3c7009c201f9f80ac86063f438/default.nix#L2 which might not match with your local one?

1 Like

Do they both reference the same nixpkgs? seems like you’re using ‘’ in https://git.sr.ht/~euandreh/vps/tree/6ba76140238b5e3c7009c201f9f80ac86063f438/default.nix#L2 which might not match with your local one?

It tried using the sane nixpkgs locally that the CI server was using.

I’ll double check that.

It tried using the sane nixpkgs locally that the CI server was using.

I’ll double check that.

I did double check, and the problem was exactly there :slight_smile: Good catch.

I had tried to build locally using a custom $NIX_PATH a few days ago,
but it didn’t work for some reason. I probably mistyped something or
anything like that.

I previously configured the CI Nix environment to point to the
nixos-unstable channel:

image: nixos/unstable
repositories:
  nixpkgs: https://nixos.org/channels/nixpkgs-unstable

Running with a custom $NIX_PATH locally fixed the issue:

NIX_PATH=nixpkgs=channel:nixos-unstable nix-build -A terraform-godaddy

Thanks @manveru for the support :slight_smile:

Hosted by Flying Circus.