Posted on November 22, 2016
Tags: nerd, haskell, nix

Reflex uses Nixpkgs to great effect to compile GHCJS and provide a working set of packages for development.

All this is available by cloning the repo and running ./try-reflex. This basically more or less just starts nix-shell, giving you a development environment.

But if you want to set up your haskell project the normal Nix way, this “sandbox” is a little annoying.

Good news is that you can import reflex-platform into your default.nix which was generated by cabal2nix. The specific git revision is pinned as well.

Just edit the default.nix and adjust the haskellPackages line to something like this:

# ...

tryReflex = import (pkgs.fetchFromGitHub {
  owner = "reflex-frp";
  repo = "reflex-platform";
  rev = "6f7aedfd57678b6e5c46dff3657dc60d40efe427";
  sha256 = "0ch1srgr8l0brk576653zpcn9v31my75xyaz30fkyqx6agf5ahav";
}) {};

haskellPackages = if compiler == "ghcjs"
                     then tryReflex.ghcjs
                     else pkgs.haskell.packages.${compiler};
# ... 

At the top of default.nix, the default compiler can also be changed to "ghcjs".

After making those changes, build and enjoy!

nix-shell
cabal configure --ghcjs
cabal build