Haskell: Difference between revisions

From NixOS Wiki
imported>Srid
m formatting
imported>Samuela
No edit summary
Line 3: Line 3:
[https://www.srid.ca/1948201.html '''Nix recipes for Haskellers'''] aims to get a beginner comfortable managing simple Haskell programs and projects using Nix.
[https://www.srid.ca/1948201.html '''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`:
<pre>
#!/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!"
</pre>
== FAQ ==
== FAQ ==



Revision as of 04:49, 3 April 2021

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.