From 4e2d6342b45e7a07a81f011480c61454f39accd8 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Thu, 20 Sep 2018 22:32:57 +0300 Subject: [PATCH] guide: Basic nix --- .gitignore | 5 +++-- posts/guides/basic-nix-haskell.md | 35 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 posts/guides/basic-nix-haskell.md diff --git a/.gitignore b/.gitignore index 2f71f5d..b792dbf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -_site -_cache +_site/ +_cache/ +dist/ diff --git a/posts/guides/basic-nix-haskell.md b/posts/guides/basic-nix-haskell.md new file mode 100644 index 0000000..6685d6f --- /dev/null +++ b/posts/guides/basic-nix-haskell.md @@ -0,0 +1,35 @@ +--- +title: Nix and Haskell +date: 2018-09-20 +--- + +The simplest way you can use haskell and nix together is by calling +`callCabal2nix` on the cabal file and using the resulting artifacts. + +I usually create two files `release.nix` and `default.nix`. At least when +developing, I avoid using the `cabal2nix` tool and instead let nix handle +calling it for me. If I ever published an actual package, I would probably +provide the autogenerated `default.nix` and nothing else. + +**Build instructions** are managed by `default.nix`. At its simplest it's just +a call to `callCabal2nix`, but might contain for example some extra cabal flags +or adding patches. + +```nix +# default.nix +{ haskellPackages }: + +haskellPackages.callCabal2nix "foo" ./. {} +``` + +**Pinning** of haskell packages and system libraries are managed by this file. +Nixpkgs requires a bootstrap `` in scope so that we can pin to a +specific commit hash. + +```nix +# release.nix +{ pkgs ? import {} }: + +# No pinning yet +pkgs.callPackage ./default.nix {} +```