Getting haskell packages via overrideCabal

Hello all,

I’m trying to build a Haskell package, from a cabal file, which has dependencies with quite strict version requirements. For example, it needs tasty-hedgehog to be between 1.2 and 1.3.

To make sure I’m passing the correct package versions to callCabal2nix, I’m creating a haskellPackages set like this:

        hsPkgs = final.haskellPackages.override {
          overrides = self: super: {
            tasty-hedgehog = final.haskell.lib.overrideCabal super.tasty-hedgehog {
              version = "1.2.0.0";
              revision = "1";
              sha256 = "";
            };
          };
        };

The first time I tried this, I got the expected error:

warning: found empty hash, assuming 'sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
error: hash mismatch in fixed-output derivation '/nix/store/7j04kcgxx9wn846mhbj8cw1r9q8z64df-tasty-hedgehog-1.2.0.0.tar.gz.drv':
         specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
            got:    sha256-zWUNs1G1r5jxZ+PaY8VA74WF3mcuPUM2vC/vpiDrCi8=

However, if I then replace the empty hash with sha256-zWUN... hash, I get

error: hash mismatch in fixed-output derivation '/nix/store/ldf283p3413apsgx8nyk7gqg8sliz5rf-tasty-hedgehog-1.2.0.0-r1.cabal.drv':
         specified: sha256-fKgQZSu9YaxDJRRsat9QVie4fzGwHQrF07WtobkX8cQ=
            got:    sha256-T7HZrlePR8DWdxJjlf4cDi50FViq8Wmh0sAVJxw1OYA=
error: 1 dependencies of derivation '/nix/store/qkh33q6irip9kydig2xyph30ri62g7ga-tasty-hedgehog-1.2.0.0.drv' failed to build

I’m not quite sure what to make of this error. The sha256-fKg... hash that I supposedly specified is not the one I used for tasty-hedgehog. Is it possible that one of the dependencies of tasty-hedgehog-1.2.0.0 also needs to be specified? If so, adding --show-trace doesn’t tell me which one.

Grateful for any help.

If you look closely, the two errors are for different derivations. One is for the source tarball, the other is for a .cabal.drv, which I assume is the FOD of the dependencies. I’m not familiar enough with cabal in nixpkgs to tell you how to override that hash, though.

Yes, you’re right, those two are errors are actually different. Not sure what the solution is, but if I figure it out I’ll put it here.

After a great deal of trial and error, I’ve got this working using these overrides:

{
  tasty-hedgehog = final.haskell.lib.overrideCabal super.tasty-hedgehog (old: {
    version = "1.3.0.0";
    sha256 = "cgH47/aozdKlyB6GYF0qNyNk2PUJsdGKD3QjBSpbZLY=";
    revision = "1";
    editedCabalFile = "NEMwxJ1HoTbt0WW+fkzcRvxd96dEl0Yl6UUxYKxOjK0=";
}

The revision = "1" was required because nix was attempting to pull revision 3 of the cabal file by default, which did not exist. The editedCabalFile parameter allows you to enter a different cash for the cabal file. Both hashes were obtained by providing incorrect hashes and copying and pasting in the correct hashes which nix then gave me when it errored. I’d like to provide more explanation for others with the same problem in future, but I still don’t really understand what I’ve done here so probably best to wait until I do, if ever.

1 Like