callCabal2nix seems to calculate a wrong dependency closure

I try to build the Haskell library hlibgit2 from source since I may have to introduce changes.

When setting up I noticed that the build fails because the library git is marked as broken. hlibgit2 however doesn’t depend on the Haskell library git.

Test expression:

let
  rev = "3d438e4cf83b732b36b0ac96f2e3ff6e6e2aef3b";
  pkgs = import (builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
    sha256 = "0nhxl3s273l3hsfrqn6r2cpvzbqxyr4kbds8hfn5jhi96ddbi2y8";
  }) {};
  gitlib-repo = builtins.fetchGit {
    url = "https://github.com/jwiegley/gitlib.git";
    submodules = true;
  };
in
  pkgs.haskellPackages.callCabal2nix "hlibgit2" "${gitlib-repo}/hlibgit2" {}

Does anybody have an idea why the build fails?
Where would I report such an issue?

You can often debug these problems by directly looking at the output of cabal2nix:

$ nix-shell -p cabal2nix --command 'cabal2nix --subpath hlibgit2 https://github.com/jwiegley/gitlib.git'
{ mkDerivation, base, bindings-DSL, fetchgit, git, lib, openssl
, process, zlib
}:
mkDerivation {
  pname = "hlibgit2";
  version = "0.18.0.16";
  src = fetchgit {
    url = "https://github.com/jwiegley/gitlib.git";
    sha256 = "039fyp8wspnchkmq1ll9747k02x4n79lslbxw4m6hia67ql5kf34";
    rev = "9d6d2aee8ed6012ea50bbcde80c47ecf83a5a595";
    fetchSubmodules = true;
  };
  postUnpack = "sourceRoot+=/hlibgit2; echo source root reset to $sourceRoot";
  libraryHaskellDepends = [ base bindings-DSL zlib ];
  librarySystemDepends = [ openssl ];
  testHaskellDepends = [ base process ];
  testToolDepends = [ git ];
  description = "Low-level bindings to libgit2";
  license = lib.licenses.mit;
}

You can see that this expression takes a git argument.

haskellPackages.callPackage naively picks haskellPackages.git to pass to this git argument, when really it should have picked the top-level git, as you’ve correctly pointed out.

You can likely fix this by making sure to pass the correct git to callCabal2nix:

pkgs.haskellPackages.callCabal2nix "hlibgit2" "${gitlib-repo}/hlibgit2" { git = pkgs.git; }
1 Like

Thanks so much for your answer, this really helps me a lot!

Is there any system for upstreaming this to nixpkgs?