Haskell dev: how to override Nixpkgs by Hackage?

This question addresses Haskell development.
I currently use cabal2nix; that way, precompiled binaries are fetched from nixpkgs for the dependencies.
But some packages are labelled broken on nixpkgs and the build aborts.
How could I override these packages using their Hackage version ?

Well very likely they are marked broken, because the version used in nixpkgs is actually broken…
Is the version from hackage that you want newer than the one in nixpkgs?

Each revision of Nixpkgs only provides one package set for each GHC version.

That is, when you pin your project environment to a specific Nixpkgs commit revision, and when you use a a specific compiler version, only one version of each package is available.

The consequence is that some packages are broken, because they are unhappy with the packages in this set. You can try to have a look why this is the case (for example, which package version bound is violated) and fix the issue. Just marking the package unbroken usually does not help. You could try to use an older (or newer) Nixpkgs commit revision.

1 Like

There are some utilities to obtain a specific version of a package in nixpkgs which you can use to overlay custom version of packages into the package set. Be mindful, though, that you will not be able to substitute those from Nix’s binary cache and also need to recompile its reverse dependencies.

pkgs.haskellPackages.override {
  overrides = self: super: {
    # Most convenient solution
    some-pkg = self.callHackage "some-pkg" "2.1.0" { };

    # If nixpkgs' snapshot of hackage doesn't know about the package yet
   other-pkg = self.callHackageDirect {
     pkg = "other-pkg";
     ver = "9.0.1";
     sha256 = "0000000000000000000000000000000000000000000000000000";

Both require import-from-derivation (IFD). If that’s not an option for you, you can also generate expressions for the respective packages and check them into your repository, calling them using self.callPackage from the overlay.