Nix Notes: Overriding Haskell Packages

Setup

In one of the projects, I use a pinned version of nixpkgs based on miso. There are two advantages to that, one is that I know that miso builds with that version, and the second one is that I can take advantage of miso’s cachix cache and not compile everything from scratch.

In the most basic form, it looks like this.

File nixpkgs.nix:

let

  bootstrap = import <nixpkgs> {};

  misoTarball = bootstrap.fetchFromGitHub {
    owner = "dmjio";
    repo = "miso";
    rev = "2c193a3253216d70f0ac182fbe9c801de00363ae";
    sha256 = "1ywksdzcfd339x1hxp5pvkgbv9mdy1y0971k8v161hg33na2p8wz";
  };

  miso = import "${misoTarball}" { } ;

  inherit (miso) pkgs;

in miso.pkgs

I can then use it in another file to compile my local Haskell package named automation-server.

Read more...

Quick Haskell Trick

The Haskell REPL (Read Print Eval Loop) - GHC interpreter, ghci invoked with:

$ ghci

or:

$ stack repl

or:

$ cabal new-repl 

or:

$ cabal repl

is an environment enabling fast iteration.

You can test a particular function and that’s cool and all, but you can also run an entire program in the interpreter. You do that with:

ghci> :main

or

ghci> main

The flow is as follows:

  1. You make some changes in your editor
  • You :r or :reload
  • You make some more changes to make it compile
  • You :r again
  • You run :main to play around with your program
  • You Ctrl-C to kill the program
  • Go back to step one

What’s a little inefficient is that to run your new version of a program you have to issue two commands: :r and :main.

Read more...

Debugging a Safe Module

TL;DR: change -XSafe to -XTrustworthy.

I’ve found myself needing to add some trace statements to System/Environment.hs. The module is marked Safe, so when you try to:

import Debug.Trace (trace)

you get the following error:

Debug.Trace: Can't be safely imported!
The module itself isn't safe.

I don’t know anything about Safe Haskell and I didn’t want to learn at the time. Removing {-# LANGUAGE Safe #-} made the Safe modules depending on System.Environment (the module I was trying to debug) fail to compile, so that wasn’t an option. Turns out you can just bypass this by marking your module as Trustworthy:

Read more...