Haskell: Difference between revisions
imported>Srid Note about IFD |
imported>Yvan-sraka Add Haskell.nix section |
||
Line 29: | Line 29: | ||
* <code>nix flake show</code> | * <code>nix flake show</code> | ||
* <code>nix flake check</code> | * <code>nix flake check</code> | ||
== Haskell.nix == | |||
<code>haskell.nix</code> can automatically translate your Cabal or Stack project and its dependencies into Nix code. | |||
See [https://github.com/input-output-hk/haskell.nix/blob/master/README.md] | |||
[[Category:Languages]] | [[Category:Languages]] | ||
[[Category:Applications]] | [[Category:Applications]] |
Revision as of 17:30, 26 September 2022
Introduction
Nix recipes for Haskellers aims to get a beginner comfortable managing simple Haskell programs and projects using Nix.
Scripting
Here's an example using nix-shell to get a redistributable Haskell script that you can run on any Nix system with `./my-script.hs`:
#!/usr/bin/env nix-shell #!nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (pkgs: [ pkgs.turtle ])" main = do # do stuff putStrLn "Hello world from a distributable Haskell script!"
FAQ
Limitations
When using cabal2nix
, Nix does not pull a cabal package by respecting the constraint specified in the cabal file (see example). Issue is discussed here. You should be using `callCabal2nix` anyway.
IFD and Haskell
callCabal2nix
, which is implicitly used for building Haskell projects, uses IFD.[1][2]. This means that since IFD is disabled by default in certain nix commands,[3] the following commands will be broken for Haskell projects whose flake output specifies multiple system attributes:
nix flake show
nix flake check
Haskell.nix
haskell.nix
can automatically translate your Cabal or Stack project and its dependencies into Nix code.
See [4]