Conquer Cabal Hell with Nix

@steshaw

Overview of talk

  1. Purely Functional Package Systems
  2. Overview of Nix
  3. How to use Nix with Haskell

Purely Functional Package Systems

Features

  • multiple variants of a package at the same time (i.e. side by side)
  • immutable packages
  • atomic upgrades/rollbacks
  • mutiple environments
  • usable as non-root

Examples

Nix

Commands

Find packages

$ nix-env --query --available 'hello*'
$ nix-env -qa 'hello*'

Install a package

$ nix-env --install hello
$ nix-env -i hello

Remove a package

$ nix-env --uninstall hello
$ nix-env -e hello

Commands (continued)

Alternatively rollback

$ nix-env --rollback

Upgrade your packages

$ nix-env --upgrade

Accelerating Haskell Development with Nix

demo time

Installing ghc-mod

nix-env -iA nixpkgs.haskell.packages.ghc784.ghc-mod

haskell

Notes (work in progress)

Nix Features

Architecture of Nix

Under the hood a little bit

  • /nix/store
  • Mention the crazy linker thing.
  • How hashing works. Why binary substiution works.
  • A -> B. What are the inputs?
    • What inputs?
    • What outputs?
    • hashing for the store
  • Caching/Memoisation.

Nix Commands

  • Installing haskell tools like ghc (different versions) and nix2cabal.
  • Usage of nix-shell
  • Usage of nix2cabal

Accelerating Haskell Development with Nix

Where are we now?

  • Using cabal sandboxes.
  • Perhaps some shared sandboxes.
  • Waiting for builds is no fun.
  • Wasting time building `lens` for each of your projects that uses it is not good.
  • Let’s not accept the status quo.
  • One option is to use Halcyon – a build cache for Cabal.

What’s not good?

  • Long build times.
  • Building the same dependencies over and over again in different sandboxes.
  • These sandboxes could be on your machine or your team members machine.
  • Or on the build box.
  • There is wastage of time but also of disk space.
  • With SSDs, disk space isn’t as cheap as it used to be.

Demo

Downsides of Nix.

  • Still early (but you’d be getting in at a great time)
  • Written in C++ and Perl (HT Raahul Kumar for pointing out that it’s C++ not C).
  • Perhaps there’s hope for a Haskell implementation — https://github.com/jwiegley/hnix.

Nix Workshop at Hack Night

  • Get set up with NixOS (and perhaps Nix on Mac/Linux/*BSD if you’re more adventurous).
  • Learn how to set up a modern Haskell development environment.
  • Hopefully, learn how to work on sources to multiple dependencies in your tree.

References