query
On this page

writeHaskell

pkgs.writers.writeHaskell

Functor
Docs pulled from | This Revision | 10 minutes ago


writeHaskell takes a name, an attrset with libraries and haskell version (both optional) and some haskell source code and returns an executable.

Examples

pkgs.writers.writeHaskell usage example

writeHaskell "missiles" { libraries = [ pkgs.haskellPackages.acme-missiles ]; } ''
  import Acme.Missiles

  main = launchMissiles
'';

Noogle detected

This is a Functor

Learn about functors

Implementation

The following is the current implementation of this function.

writeHaskell =
    name:
    {
      ghc ? pkgs.ghc,
      ghcArgs ? [ ],
      libraries ? [ ],
      makeWrapperArgs ? [ ],
      strip ? true,
      threadedRuntime ? true,
    }:
    let
      appendIfNotSet = el: list: if elem el list then list else list ++ [ el ];
      ghcArgs' = if threadedRuntime then appendIfNotSet "-threaded" ghcArgs else ghcArgs;

    in
    makeBinWriter {
      compileScript = ''
        cp $contentPath tmp.hs
        ${(ghc.withPackages (_: libraries))}/bin/ghc ${lib.escapeShellArgs ghcArgs'} tmp.hs
        mv tmp $out
      '';
      inherit makeWrapperArgs strip;
    } name;