Can't fetch latest Rust package from github

I keep getting hash mismatch while trying to fetch ratty from the latest release:
configuration.nix:

  nixpkgs.overlays = [
    (final: prev: {
      ratty = prev.ratty.overrideAttrs (oldAttrs: rec {
        version = "master";
  
        src = prev.fetchFromGitHub {
          owner = "orhun";
          repo = "ratty";
          rev = "4b6808576881fb3f162d3936c58d7d0445d3377e";
          hash = "sha256-Y87hNgAFwPFGD1cEnFn9zU0ctVuODyheUTUX0uKkRN8=";
        };
  
        cargoDeps = oldAttrs.cargoDeps.overrideAttrs (lib.const {
          name = "ratty-vendor.tar.gz";
          inherit src;
          outputHash = "sha256-fyZo+cdxakSsR3LNAIAw/l6bdS/awnWZMGoKDlcyRH4=";
        });
      });
    })
  ];

error messages:

error: hash mismatch in fixed-output derivation '/nix/store/zzlz5hkhiaacl574hksmjh5ggy0jnxmf-ratty-master-vendor-staging.drv':
         specified: sha256-/9ekk3B96OanoEXxRDd8eN0gx4IK0qfysOd6DkIZg+k=
            got:    sha256-fyZo+cdxakSsR3LNAIAw/l6bdS/awnWZMGoKDlcyRH4=
error: Cannot build '/nix/store/nwiqqp11fvbyg4glm7480j2b7l57i5ry-ratty-vendor.tar.gz.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/9bhbb1wr51al9va7bjkcvchyr3298ib2-ratty-vendor.tar.gz
error: Build failed due to failed dependency
error: Cannot build '/nix/store/0djghmya0q6dxv5xyb5nnf51w9n83ddk-ratty-master.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/6gb2bi3icf6m805m1n3c2506cbni51sz-ratty-master

Even after I put the correct hash in outputHash, I still get the same error. Can somebody help me build this package?

EDIT: forgot to add this

nixos-version
26.05.20260521.b1f7c38 (Yarara)

Overriding a cargoDeps doesn’t work. You should call fetchCargoVendor directly. You should also:

  • Use the finalAttrs pattern instead of rec.
  • Reference things like fetchFromGitHub (or, in the code I’m about to present, rustPlatform) from final instead of prev, unless and except for where you’re overriding them.
  • You can override src, and I recommend it, particularly when you use the same version numbering convention as Nixpkgs and don’t invent a ‘master’ version.
{
  ratty = prev.ratty.overrideAttrs (finalAttrs: oldAttrs: {
    version = "0.4.0";

    src = oldAttrs.src.overrideAttrs {
      hash = "sha256-Y87hNgAFwPFGD1cEnFn9zU0ctVuODyheUTUX0uKkRN8=";
    };

    cargoDeps = final.rustPlatform.fetchCargoVendor {
      inherit (finalAttrs) pname version src;
      hash = "sha256-fyZo+cdxakSsR3LNAIAw/l6bdS/awnWZMGoKDlcyRH4=";
    };
  });
}
1 Like

Thank you it worked! By the way, is there a way for me to automatically fetch the latest release along with its hashes when I’m updating the system?

You could try nix-update for that.

1 Like

Thank you I will look into it!