Overiding the version of Haskell's Primitive package

Hello, I am trying to package SimpleX for nixos and am running into a snag due to the version of haskellPackages.primitive being too high, however, when I try to adjust the version like the rest, I either get a infinite recursion or I get a host of weird compile errors when I try to compile it from scratch (This package indirectly depends on multiple versions of the same package. This is very likely to cause a compile failure.)

Any idea on what I am doing wrong, or if this is even possible? Full current package version below:

{
  lib,
  haskell,
  stdenv,
  fetchFromGitHub,
}:

let
  version = "6.4.1";

  smpCC = haskell.packages.ghc963.override {
    overrides = _final: _prev: {
      deepseq = _final.developPackage {
        root = fetchFromGitHub {
          owner = "haskell";
          repo = "deepseq";
          tag = "v1.4.8.1";
          sha256 = "sha256-XJFTH2CWsqDgtgr0qpA53KpAX7dtoi2SGFqZLKoFZdA=";
        };

        cabal2nixOptions = "--no-check";
      };

      primitive = _final.developPackage {
        root = fetchFromGitHub {
          owner = "haskell";
          repo = "primitive";
          tag = "v0.8.0.0";
          sha256 = "sha256-Vhywv1FFZY5ofCU5dsQWdKwk4bsbMnpdUpFyUTaKZX4=";
        };

        cabal2nixOptions = "--no-check";
      };

      aeson = _final.developPackage {
        root = fetchFromGitHub {
          repo = "aeson";
          owner = "simplex-chat";
          rev = "aab7b5a14d6c5ea64c64dcaee418de1bb00dcc2b";
          hash = "sha256-OTuJENv5I+9bWy6crllDm1lhkncmye33SCiqh1Sb50s=";
        };

        source-overrides = {
          Diff = "0.4.1";
          th-abstraction = "0.6.0.0";
          witherable = "0.4.2";
          nothunks = "0.1.5";
          hedgehog = "1.4";
        };
      };

      hs-socks = _final.developPackage {
        root = fetchFromGitHub {
          repo = "hs-socks";
          owner = "simplex-chat";
          rev = "a30cc7a79a08d8108316094f8f2f82a0c5e1ac51";
          hash = "";
        };
      };

      direct-sqlcipher = _final.developPackage {
        root = fetchFromGitHub {
          repo = "direct-sqlcipher";
          owner = "simplex-chat";
          rev = "f814ee68b16a9447fbb467ccc8f29bdd3546bfd9";
          hash = "sha256-9/K1pnUnUTLj6OV5neQF6bDrQvtgi0a4VekJQuuGPE4=";
        };
      };

      sqlcipher-simple = _final.developPackage {
        root = fetchFromGitHub {
          repo = "sqlcipher-simple";
          owner = "simplex-chat";
          rev = "a46bd361a19376c5211f1058908fc0ae6bf42446";
          hash = "sha256-9JV2odagCkUWUGEe8dWmqHfjcBmn6rf6FAEBhxo6Gfw=";
        };

        cabal2nixOptions = "--no-check";
      };

      warp-tls = _final.developPackage {
        root =
          (fetchFromGitHub {
            repo = "wai";
            owner = "yesodweb";
            rev = "ec5e017d896a78e787a5acea62b37a4e677dec2e";
            hash = "sha256-fQmWamDI1OHmnWZKsROukFh6JAUCi7IyjjJ5J2+9bLI=";
          })
          + "/warp-tls";
      };

      warp = _final.developPackage {
        root =
          (fetchFromGitHub {
            repo = "wai";
            owner = "simplex-chat";
            rev = "2f6e5aa5f05ba9140ac99e195ee647b4f7d926b0";
            hash = "sha256-xKvzAZBnynDAAB1jIsir0AwYstcNW8SZC/cH12QmL6U=";
          })
          + "/warp";
      };
    };
  };

  simplexmq = smpCC.developPackage {
    root = fetchFromGitHub {
      repo = "simplexmq";
      owner = "simplex-chat";
      tag = "v${version}";
      hash = "sha256-g25/CTUlWior+wk6fru39zvAIj99J+penu+W8HaqlNI=";
    };
  };
in
stdenv.mkDerivation {
  pname = "simplex-server";
  inherit version;

  src = simplexmq;

  installPhase = ''
    mkdir -p "$out"
  '';

  meta = {
    homepage = "https://github.com/simplex-chat/simplexmq";
    description = "SimpleX Server for routing messages";
    license = lib.licenses.agpl3Only;
    platforms = lib.platforms.linux;
  };
}

developPackage is a somewhat bad fit for what you are trying to do. It’s a wrapper around callCabal2nixWithOptions with

  • a convenience function to switch to the included development environment if you are using nix-shell. This means all packages in your overlay will switch to development environments if you evaluate it using nix-shell (since the switch somewhat suboptimally relies on the IN_NIX_SHELL environment variable). This will break your overlay. It’s better to use callCabal2nixWithOptions directly for your use case and developPackage (if at all) only for the outermost package, the entry point of the shell.nix/default.nix.
  • source-overrides adds an overlay that only applies to the dependencies of the given package. This is the source of the inconsistent dependency error. If you are going to change dependency versions, this needs to be done globally, i.e. in the main overlay since Haskell requires a globally consistent package set.

You should be able to change every instance of developPackage to

final.callCabal2nixWithOptions "<package>-<version>.nix" root cabal2nixOptions { }

As for the infinite recursion, you’ll obtain the precise diagnosis by evaluating with --show-trace. Circular dependencies can happen in Haskell packages due to their test suites. This is also the case for most primitive versions: the test suite causes a circular dependency on base-orphans. The fix is to add dontCheck to the overlay entry for primitive, like we do in nixpkgs.

Ok thank you I will try this a little later. What means of overriding the versions do I need to use then? Do I need to grab the GitHub source for each one or is there a source overrides for this function? Unfortunately the package has need for many different versions than what the current nixpkgs provides.

You can use haskell.lib.compose.packageSourceOverrides which develoPackage uses internally or just manually write out the callHackage calls in your overlay.