How do get a Haskell package from a git repository subdirectory?

I’ve been getting Haskell packages from Github with this pattern:

a-package =
  cabal2nix "a-package" (prev.fetchgit {
    url = "https://github.com/alice/a-package.git";
    sha256 = "sha256-...";
    rev = "...";
  }) { };

This works fine, except there’s a package in a repository I’m trying to get with it’s cabal file in a subdirectory src, instead of the usual root of the repository.

I’ve tried this:

a-package =
  cabal2nix "a-package" (prev.fetchgit {
    url = "https://github.com/alice/a-package.git";
    sha256 = "sha256-...";
    rev = "...";
  } + "/src") { };

But this strangly results in the following error:

> cabal2nix: nix-prefetch-url: createProcess: posix_spawnp: does not exist (No such file or directory)

Any ideas?

I use callCabal2nix like the following:

overrides = self: super: {
  a-package = self.callCabal2nix "a-package" ((
    builtins.fetchgit {
      url = "https://github.com/alice/a-package.git";
      ref = "branch";
      rev = "...";
    }) + "/src") {};
};

@clinton

But this strangly results in the following error:

cabal2nix: nix-prefetch-url: createProcess: ...

My guess is that one of the following things is happening:

  1. There is actually no .cabal file in the src/ subdirectory. Or cabal2nix can’t find it for some reason.

  2. cabal2nix is not actually getting passed the src/ subdirectory correctly. I’d play around with your call to pkgs.fetchgit just to make sure the output source derivation is exactly as you expect.

  3. You’ve forgotten to update the sha256 argument, and you’re getting some sort of unexpected path.