diff --git a/2022-12-15-stacklock2nix.md b/2022-12-15-stacklock2nix.md index b4b8e6a..73b8a19 100644 --- a/2022-12-15-stacklock2nix.md +++ b/2022-12-15-stacklock2nix.md @@ -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 diff --git a/2022-12-20-building-dhall-with-stacklock2nix.md b/2022-12-20-building-dhall-with-stacklock2nix.md index c4b0553..0b5a1fe 100644 --- a/2022-12-20-building-dhall-with-stacklock2nix.md +++ b/2022-12-20-building-dhall-with-stacklock2nix.md @@ -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 diff --git a/2022-12-26-building-pandoc-with-stacklock2nix.md b/2022-12-26-building-pandoc-with-stacklock2nix.md index 24ba82e..ca53b97 100644 --- a/2022-12-26-building-pandoc-with-stacklock2nix.md +++ b/2022-12-26-building-pandoc-with-stacklock2nix.md @@ -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 ------------------------------------------------------ @@ -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: - + + -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 git@github.com:cdepillabout/dhall-haskell.git -$ cd dhall-haskell/ +$ git clone git@github.com: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