Nix Haskell Development (2020)

Did this ever get published (e.g., on the Nix Wiki), or is this the most up-to-date version of this excellent tutorial?

1 Like

This has not been published to the Nix Wiki and I think I should update it for 2021. Its not that anything above wouldn’t work, but that there are easier and more concise ways of doing Haskell development in Nix in practice. I want to both provide a shorted version for those wanting to get started quickly, but also leave the more verbose version.

In short, one of my new years resolutions is to revisit this and add what I have learned over the past year. If this is not done by the end of the month, feel free to ping me.

11 Likes

The current tooling works well if all of your dependencies can be compiled with the versions of packages specified on stackage. But if some of them don’t (for example if the versions are too new), it can go horribly wrong. You’ll need to manually pick specific versions of packages, and override them in the package set, similar to what you’d usually do in stack.yaml. This process is tedious, error-prone, and needs to be done every time nixpkgs updates. This is also what a dependency solver is for. I think we definitely need something that can take advantage of cabal’s solver to help us generate a build plan. Currently only haskell.nix can do this and I think nixpkgs definitely need this as well.

This issue has been addressed in greater detail in my preview post: A summary of the problems I met while using the current nixpkgs Haskell infrastructure (And my thoughts on how to solve them).

1 Like

Thanks, the trick with overriding mkDerivation helped to pass a custom environment variable into project build with callCabal2nix inside overlay, but this solution causes nix to rebuild all dependencies (hours…).

So an alternative is appreciated.

As for me I think callCabal2nix is very limited in customization.
I don’t understand why passing environment variable is not possible.

.overrideAttrs is not working inside overlay.

I need a way to pass git commit hash. Project is fetched from git as an archive and git meta information is erased, but gitlab CI has CI_COMMIT_SHA env variable, but nix cleans env before launching GHC.

@daniil If you throw together an example of what you’re trying to do in a repo on GitHub (and show exactly what is failing), someone may take a look and try to help you out.

Hi @Skyfold! Wanna write another post for 2022 in 2023?

3 Likes
  • This was written 3 years ago.
  • Wasn’t this a controversial opinion then? What about now? Has anything changed since?
  • As far as I can see, there are still two competing approaches to Nix and Haskell: nixpkgs.haskellPackages vs. haskell.nix. Both exist and haskellPackages isn’t even close to being abandoned or dead.
  • As far as I can see, most tutorials today (including those showing nix flakes with Haskell) are geared towards haskellPackages. (Of course the old Gonzales tutorial, which brought lots of people into the fold, was about haskellPackages but that’s outdated now)
  • This is very confusing to a newcomer in 2023 who has no idea where to begin.
1 Like

Let me try to answer some of your questions. I’ll try to give you objective answers (but my answers will definitely be colored by my own experience).

Sort of. Especially if you consider that this opinion was coming from one of the Haskell maintainers in Nixpkgs.

To give a little historical context, at the time I originally wrote this, the Haskell package set in Nixpkgs wasn’t as big as it is now, and non-main compilers weren’t as well supported. So it made more sense to use haskell.nix if you wanted to use any compiler other than the main GHC in Nixpkgs. In my experience, a lot of people who were using Haskell professionally weren’t using the main GHC in Nixpkgs, but they were either stuck on an older compiler, or using the absolute latest compiler.

Since the above was written there have been a bunch of improvements in Nixpkgs:

  • Platforms other than x86_64-linux are much better supported.
  • There are many more Haskell packages available and compiling correctly.
  • Static-linking with musl works really well now.
  • The non-main GHCs generally have more packages that compile with them. For instance, HLS and its transitive dependency tree will generally compile on all GHCs it supports in Nixpkgs.
  • People have seemed to get pretty comfortable with functions like haskellPackages.callCabal2nix, haskellPackage.callHackage, haskellPackages.developPackage, and haskellPackages.shellFor. You’re starting to really see a lot of use of these, which makes things pretty easy.

In my experience, for a year or two after haskell.nix came out, there were a wave of people that jumped ship from Nixpkgs to haskell.nix. haskell.nix has a bunch of nice things going for it, but it also has a few downsides. In the last two years or so, there have been a non-trivial number of people that have moved back to Nixpkgs.

My guess is that if you look at all serious Haskell projects building with Nix, about half use haskell.nix, and half use Nixpkgs. Or maybe slightly more use haskell.nix.

There are two other recent solutions that may be of interest as well. Both use the Nixpkgs Haskell infrastructure under-the-hood:

Yeah, sorry about that :slight_smile:

My personal recommendation is here:

My recommendations haven’t changed since I wrote this, except I’d say that if you have a Stack-based project and Nixpkgs doesn’t work for you, you might want to check out stacklock2nix before diving into haskell.nix.

3 Likes

And third:

4 Likes

having battled with haskell.nix, and see it turned into an absolute monster, which uses a ton of IFD (bad news for all kinds of reasons).

if you not invested or tied to any particular nix haskell build tool…

then take a look https://horizon-haskell.net/

it’s new, but it’s already proving it’s faster, reliable, stable and flexible…

2 Likes

It’s not immediately clear from their website. Does the horizon thing allow building things like existing stack applications?

DM me, with your details, and I’ll show you a demo.

Do you have a particular stack built app in mind? link me

A post was split to a new topic: Setting up Haskell language server for GHC 9.2.7