The following commit adds some Nix code to the Dhall repo that can be used to build with Nix1:
The most interesting file in this commit is
nix/overlay.nix. This is the file I recommend taking a look at to get a feel for using
stacklock2nix. This newly-added Nix code is based on the advanced example of
stacklock2nix. This post explains how to use this newly-added Nix code.
What can you do with this?
First, clone the above repo locally with the following commands:
$ git clone firstname.lastname@example.org:cdepillabout/dhall-haskell.git $ cd dhall-haskell/ $ git checkout build-with-stacklock2nix $ git submodule update --init
From here, you can use the
flake.nix file to build the Dhall tools:
$ nix build -L
After building, all the Dhall tools should be available:
$ ls result/bin/ csv-to-dhall dhall dhall-docs dhall-lsp-server dhall-to-bash dhall-to-csv dhall-to-json dhall-to-nix ...
You can also use the
default.nix file with
You can use
nix develop to jump into a development shell that has tools like
cabal-install and HLS available:
$ nix develop -L
Or you could do the same thing with
From here, you can build all the Dhall tools with
$ cabal build all ... $ cabal run dhall -- --version 1.41.2
You can also use other normal commands like
cabal repl, etc.
The repo is also setup to be able to build with
$ stack --nix build
And run tests:
$ stack --nix test
Dhall is a non-trivial, multi-package Haskell project. Building it with
stacklock2nix is relatively straight-forward. A few Nix overrides are necessary for getting everything to build. As long as you have a
stacklock2nix makes it easy to build a Haskell project with Nix. Even a large, multi-package Haskell project.
The Haskell dependency versions are controlled by the
stack.yaml file. Bumping the Stackage resolver in
stack.yaml is all that is needed to build with newer Haskell dependencies. This is much easier than manually keeping dependencies in sync between Haskell and Nix.
Dhall actually already has a nice infrastructure for building with Nix. In practice, this existing infrastructure should be used instead of
stacklock2nix. The commit from this blog post is purely to show how
stacklock2nixcould be used on a non-trivial Haskell project. (There is also a parent commit that deletes all the existing Nix infrastructure in the Dhall repo, just to make everything a little easier to understand.)↩︎
nix-shell, so you can run
nix-shell. That is to say, you don't have to be inside
nix-shellbefore you run any of the