Skip to content

Instantly share code, notes, and snippets.

@codygman
Last active October 12, 2020 22:11
Show Gist options
  • Save codygman/3c7dd2a24b5802f9d8f68cc721be4b03 to your computer and use it in GitHub Desktop.
Save codygman/3c7dd2a24b5802f9d8f68cc721be4b03 to your computer and use it in GitHub Desktop.
Different ways to build haskell projects with nix

nix for haskell development

There are numerous options for using nix with Haskell, which themselves have numerous options:

cabal2nix (Nix manual recommended)

Sadly, there aren’t instructions on adding a source override for this method and it instead switches to using developPackage

how do you override a Haskell dependency version with this method?

This introduces some version.nix file and it’s unclear how to create it

#...
# pinning nixpkgs using new Nix 2.0 builtin `fetchGit`
pkgs = import (fetchGit (import ./version.nix)) { };
#...

searching nix 2.0 fetchgit version.nix doesn’t result in anything useful for me

searching github for filename:version.nix doesn’t help me figure out how to write the file

how do you create a version.nix file that works with this example from the nix manual?

stack --nix (doesn’t really use nix for Haskell deps)

Does not use Nix cache and instead rebuilds Haskell dependencies unnecessarily

Even with Nix integration enabled, Stack will still build all of your project’s Haskell dependencies itself, rather than using the Nix cache. - Typeclasses.com on stack –nix

However it does use the cache for non-haskell dependencies.

haskell.nix (Does a lot for you, but can seem impenetrable)

stack

subverting stack by pre-loading ghc pkg db so it functions as frontend

Why? 2 reasons:

  1. You really like stack’s UX or your team prefers it’s ux:
  2. You want to download cached Haskell packages rather than rebuilding them

is there another way? Maybe you can use haskell.nix with stack.nix?

cabal

cabal’s built in nix integration (don’t know much about this)

snack (seems super cool, is allegedly experimental, but seems very very good)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment