Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cdepillabout committed Dec 26, 2022
1 parent 90f8dd5 commit 2d89cc3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 72 deletions.
6 changes: 5 additions & 1 deletion 2022-12-15-stacklock2nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ various Haskell projects. Check out each one for a realistic example of using
multiple packages. This is good for developers who need ultimate
flexibility.

3. `spago` (coming soon)
3. [`pandoc`](./2022-12-26-building-pandoc-with-stacklock2nix)

This post is similar to the post about `purescript`, but it sets up
pandoc to be statically linked. This would be a good example to
follow for people that want to distribute fully statically-linked
Haskell binaries.

## Footnotes

Expand Down
2 changes: 1 addition & 1 deletion 2022-12-20-building-dhall-with-stacklock2nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ draft: false
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).*
[building Pandoc with `stacklock2nix`](./2022-12-26-building-pandoc-with-stacklock2nix).*

This post uses [`stacklock2nix`](https://github.com/cdepillabout/stacklock2nix)
to build [Dhall](https://github.com/dhall-lang/dhall-haskell) and all its
Expand Down
101 changes: 31 additions & 70 deletions 2022-12-26-building-pandoc-with-stacklock2nix.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
------------------------------------------------------
title: Building Spago with stacklock2nix
summary: Use stacklock2nix to build Spago while statically linking
title: Building Pandoc with stacklock2nix
summary: Use stacklock2nix to build a fully statically-linked Pandoc
tags: nixos, haskell
draft: false
------------------------------------------------------
Expand All @@ -11,94 +11,55 @@ 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.
to build [Pandoc](https://github.com/jgm/pandoc) with Nix. Pandoc is a tool for
converting from one markup format to another. It is one of the most widely-used
tools written in Haskell. This post explains how to use `stacklock2nix` to
build Pandoc, but with a twist that Pandoc will be fully statically-linked.
This means that you can take the Pandoc binary built with Nix and use it
on any Linux distribution.

The following commit adds some Nix code to the Dhall repo that can be used to
build with Nix[^1]:
The following commit adds a `flake.nix` to the Pandoc repo that can be used to
build with Nix and statically-link:

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

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.
This `flake.nix` is based on the
[easy example](https://github.com/cdepillabout/stacklock2nix/tree/main/my-example-haskell-lib-easy)
of `stacklock2nix`. This post explains how to use this `flake.nix`.

## What can you do with this?
## What can you do with this `flake.nix`?

First, clone the above repo locally with the following commands:

```console
$ git clone [email protected]:cdepillabout/dhall-haskell.git
$ cd dhall-haskell/
$ git clone [email protected]:cdepillabout/pandoc.git
$ cd pandoc/
$ git checkout build-with-stacklock2nix
$ git submodule update --init
```

From here, you can use the `flake.nix` file to build the Dhall tools:
This `flake.nix` is very similar to the one added for
[building PureScript](./2022-12-16-building-purescript-with-stacklock2nix).
You can run all the same commands, like `nix build`, or `nix develop` and then
`cabal build all`.

```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:
The big difference is that this `flake.nix` for Pandoc is setup to statically-link
the binaries it produces. So if you build the binary, you can see that it has
been statically-linked:

```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
$ nix build
...
$ cabal run dhall -- --version
1.41.2
$ file result/bin/pandoc
result/bin/pandoc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
```

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
```
You can see that it says "statically linked".

And run tests:

```console
$ stack --nix test
$ docker run -it -v `pwd`/result:/pandoc ubuntu /pandoc/bin/pandoc --version
pandoc 3.0
```

## Conclusion
Expand Down

0 comments on commit 2d89cc3

Please sign in to comment.