Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cdepillabout committed Dec 25, 2022
1 parent dc00925 commit 90f8dd5
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 9 deletions.
10 changes: 4 additions & 6 deletions 2022-12-16-building-purescript-with-stacklock2nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ draft: false
------------------------------------------------------

*This is the first post in a
[series about `stacklock2nix`](./2022-12-15-stacklock2nix).*
[series about `stacklock2nix`](./2022-12-15-stacklock2nix).
The next post is about
[building Dhall with `stacklock2nix`](./2022-12-20-building-dhall-with-stacklock2nix).

<!-- The next post is about
[who would find PureNix easy to use](./2022-01-05-who-would-like-purenix). -->
[building Dhall with `stacklock2nix`](./2022-12-20-building-dhall-with-stacklock2nix).*

This post uses [`stacklock2nix`](https://github.com/cdepillabout/stacklock2nix)
to build the PureScript compiler with Nix. PureScript is a non-trivial Haskell
to build the [PureScript compiler](https://github.com/purescript/purescript)
with Nix. PureScript is a non-trivial Haskell
project, but it is not _too_ complicated. It is good as an initial example of
using `stacklock2nix`.

Expand Down
8 changes: 5 additions & 3 deletions 2022-12-20-building-dhall-with-stacklock2nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ draft: false
[series about `stacklock2nix`](./2022-12-15-stacklock2nix).
The previous post is about
[building PureScript with `stacklock2nix`](./2022-12-16-building-purescript-with-stacklock2nix).
The next post is about
[building Spago with `stacklock2nix`](./2022-12-24-building-spago-with-stacklock2nix).*

This post uses [`stacklock2nix`](https://github.com/cdepillabout/stacklock2nix)
to build Dhall and all its tools with Nix. The Dhall project is a good
example for `stacklock2nix`, since it is comprised of quite a few different
Haskell packages.
to build [Dhall](https://github.com/dhall-lang/dhall-haskell) and all its
tools with Nix. The Dhall project is a good example for `stacklock2nix`, since
it is comprised of quite a few different Haskell packages.

The following commit adds some Nix code to the Dhall repo that can be used to
build with Nix[^1]:
Expand Down
128 changes: 128 additions & 0 deletions 2022-12-26-building-pandoc-with-stacklock2nix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
------------------------------------------------------
title: Building Spago with stacklock2nix
summary: Use stacklock2nix to build Spago while statically linking
tags: nixos, haskell
draft: false
------------------------------------------------------

*This is the third and final post in a
[series about `stacklock2nix`](./2022-12-15-stacklock2nix).
The previous post is about
[building Dhall with `stacklock2nix`](./2022-12-20-building-dhall-with-stacklock2nix).*

This post uses [`stacklock2nix`](https://github.com/cdepillabout/stacklock2nix)
to build [Spago](https://github.com/purescript/spago) with Nix. Spago is a
popular build tool for PureScript.
example for `stacklock2nix`, since it is comprised of quite a few different
Haskell packages.

The following commit adds some Nix code to the Dhall repo that can be used to
build with Nix[^1]:

<https://github.com/cdepillabout/dhall-haskell/commit/e1a7c31d68ad2da9c748dddcca01668da0ca53d6>

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](https://github.com/cdepillabout/stacklock2nix/tree/main/my-example-haskell-lib-advanced)
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:

```console
$ git clone [email protected]: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:

```console
$ nix build -L
```

After building, all the Dhall tools should be available:

```console
$ 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 `nix-build`:

```console
$ nix-build
```

You can use `nix develop` to jump into a development shell that has tools like
`cabal-install` and HLS available:

```console
$ nix develop -L
```

Or you could do the same thing with `nix-shell`:

```console
$ nix-shell
```

From here, you can build all the Dhall tools with `cabal`:

```console
$ cabal build all
...
$ cabal run dhall -- --version
1.41.2
```

You can also use other normal commands like `cabal test`, `cabal repl`, etc.

The repo is also setup to be able to build with `stack`[^2]:

```console
$ stack --nix build
```

And run tests:

```console
$ stack --nix test
```

## Conclusion

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 `stack.yaml`
and `stack.yaml.lock` file, `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.

## Footnotes

[^1]: 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
`stacklock2nix` could 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.)

[^2]: Note that `stack` internally runs `nix-shell`, so you can run `stack`
outside of `nix-shell`. That is to say, you don't have to be inside
`nix-shell` before you run any of the `stack` commands.

0 comments on commit 90f8dd5

Please sign in to comment.