Haskell: Difference between revisions
m style: add missing "$" prefix, use lang=console, remove unneeded spaces - where needed |
m →Scripting: fix indentation |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 32: | Line 32: | ||
To remove the additional latency overhead of a nix-shell, add GHC to <code>environment.systemPackages</code> and call <code>runghc</code> in the shebang.<syntaxhighlight lang="nix"> | To remove the additional latency overhead of a nix-shell, add GHC to <code>environment.systemPackages</code> and call <code>runghc</code> in the shebang.<syntaxhighlight lang="nix"> | ||
environment.systemPackages = with pkgs; [ | |||
... | |||
(ghc.withPackages (hsPkgs: with hsPkgs; [ | |||
turtle # Faster startup time with all external shell commands | |||
shh # Piping operators and other goodies | |||
shh-extras # Try shh as an interactive shell | |||
... # ...anything else you want! | |||
]) | |||
]; | |||
</syntaxhighlight>Here's a basic example using the Shh module rather than Turtle, so it can use the pipe operator:<syntaxhighlight lang="haskell"> | </syntaxhighlight>Here's a basic example using the Shh module rather than Turtle, so it can use the pipe operator:<syntaxhighlight lang="haskell"> | ||
#!/usr/bin/env runghc | #!/usr/bin/env runghc | ||
| Line 171: | Line 171: | ||
For instance you can define your various projects in subfolders <code>./frontend</code> and <code>./backend</code> (you can use cabal init to create the content in each folder), then create a file <code>cabal.project</code> containing: | For instance you can define your various projects in subfolders <code>./frontend</code> and <code>./backend</code> (you can use cabal init to create the content in each folder), then create a file <code>cabal.project</code> containing: | ||
{{file|cabal.project| | {{file|cabal.project|haskell| | ||
<nowiki> | <nowiki> | ||
packages: | packages: | ||
| Line 226: | Line 226: | ||
=== Using haskell-flake (flake-parts) === | === Using haskell-flake (flake-parts) === | ||
[https:// | [https://haskell.nixos.asia/ haskell-flake] is a project that aims to simplify writing Nix for Haskell development through use of [[Flake Parts|flake-parts module system]]. It uses <code>callCabal2nix</code> and <code>shellFor</code> under the hood while exposing friendly module options API. For an overview of Flakes, see the [[Flakes]] wiki page. | ||
* For existing Haskell projects, initialize with: | * For existing Haskell projects, initialize with: | ||
| Line 300: | Line 300: | ||
==== Further reading ==== | ==== Further reading ==== | ||
* [https://github.com/srid/haskell-template | * [https://github.com/srid/haskell-template Example Haskell project with a development environment] | ||
* [https://github.com/srid/haskell-multi-nix | * [https://github.com/srid/haskell-multi-nix Example cabal.project multi-package Haskell project] | ||
* [https:// | * [https://haskell.nixos.asia/start Getting started with haskell-flake]. | ||
* [https:// | * [https://haskell.nixos.asia/dependency Overriding dependencies in a haskell-flake] | ||
* [https://flake.parts/options/ | * [https://flake.parts/options/haskell-flake haskell-flake options reference] | ||
== Overrides == | == Overrides == | ||