cabal flags and ghci - Nix

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Torsten Schmits

I'm trying to run ghcid/ghci in a nix-shell, which always presents the problem of test dependencies being invisible. As a workaround I wanted to try and use a cabal flag that adds those same dependencies to the library. Now the problem is that I have to activate that flag for the ghci session.

My intuition was that I would have to enable the flag on the package I pass to nix-shell as dependency, like so:

ghc.shellFor {
  packages = p: [(enableCabalFlag p.mainPackage "devdeps")];
  hook = "ghcid ...";
}

but that doesn't have the desired effect.
Anyone have an idea?

Mats Rauhala

I usually do something along the lines of

mkShell {
  name = "foo-shell";
  paths = with pkgs; [ ghcid haskellPackages.cabal-install (haskellPackages.ghcWithPackages( _: mypackage.buildInputs ++ mypackage.propagatedBuildInputs)];
}

It's the propagatedBuildInputs which brings the test deps

Torsten Schmits

curious, propagatedBuildInputs doesn't seem to contain the test deps here (I looked at them with builtins.trace). Do you define them something like this?

tests:
  suite-x:
    dependencies:
      - hedgehog
Mats Rauhala

Yeah, although with cabal, but shouldn't make a difference

Torsten Schmits

hmm I think I have dontCheck somewhere, maybe that thwarts my efforts

Mats Rauhala

Sounds sensible enough

Torsten Schmits

looks like there's some weirdness going on in ghc.shellFor that I'm unable to figure out.
Despite the test deps being present in buildInputs of the package derivation and shellFor forwarding those to mkDerivation, and appending the buildInputs manually passed to shellFor (where I also tried adding hedgehog explicitly), the test dep isn't visible to ghci.

However, replacing shellFor with mkDerivation and using your ghcWithPackages method seems to work just fine, so I guess I'll be using that for now :shrug:

in any case, thanks :100: for your input!