GHC with libdw support

I want to provide a stack trace from my Haskell program when an error occurs. I plan to use GHC.ExecutionStack. The documentation says:

Your GHC must have been built with libdw support for this to work.

user@host:~$ ghc --info | grep libdw
,(“RTS expects libdw”,YES)

Q1: I didn’t see libdw in the NixOS package repo, but I did see libdwarf. Is that the right library?

I added libdwarf to my NixOS configuration and did nixos-rebuild switch --upgrade, but that didn’t get me a GHC with libdw support.

$ ghc --info | grep libdw
 ,("RTS expects libdw","NO")

Note: I’ve seen this issue about getting GHC with DWARF support into NixOS. A pull request was generated.

Q2: Is my best bet to create my own Nix derivation that builds an appropriate GHC? If so, can anyone point me to a similar Nix derivation that I can use as a guide? A derivation that builds GHC would be ideal, because I think I could figure out how to include libdw.

I was able to build a Debian-based docker image with GHC and libdw support, so I might fall back to using that if I can’t figure out how to do this the Nix way.

Hey,

Answering Q1:

Have a detailed look at the issue you linked, where I mention in the shown diff:

elfutils provides libdw

The PR you mentioned was reverted because it broke things: ghc: compile with DWARF support by default by domenkozar · Pull Request #68362 · NixOS/nixpkgs · GitHub

Answering Q2:

The best approach is to work off the PRs

and fixing the remaining problems mentioned in there.

There is nothing inherently difficult in building GHC with DWARF support, somebody just has to put in the time to ensure it doesn’t break anything on any platform. Then it can be merged to nixpkgs master.

Hope that helps!

2 Likes

See ghc: compile with DWARF support by default · NixOS/nixpkgs@7217090 · GitHub, this finally works with 8.10 or later :slight_smile:

2 Likes

Good, I’ve linked that into the old PRs now.