2022-03-08 04:53:07 +00:00
|
|
|
final: _: let
|
|
|
|
inherit (final) lib pkgs;
|
2022-03-08 01:42:46 +00:00
|
|
|
in {
|
2020-05-27 13:20:08 +00:00
|
|
|
haskellList = list: ''["${builtins.concatStringsSep ''", "'' list}"]'';
|
2021-01-04 18:20:00 +00:00
|
|
|
# writeHaskell takes a name, an attrset with libraries and haskell version (both optional)
|
|
|
|
# and some haskell source code and returns an executable.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
# writeHaskell "missiles" { libraries = [ pkgs.haskellPackages.acme-missiles ]; } ''
|
|
|
|
# import Acme.Missiles
|
|
|
|
#
|
|
|
|
# main = launchMissiles
|
|
|
|
# '';
|
2022-03-08 01:42:46 +00:00
|
|
|
writeHaskell = name: {
|
|
|
|
libraries ? [],
|
|
|
|
ghc ? pkgs.ghc,
|
|
|
|
ghcArgs ? [],
|
|
|
|
ghcEnv ? {},
|
|
|
|
}:
|
2021-05-18 14:33:28 +00:00
|
|
|
pkgs.writers.makeBinWriter
|
2022-03-08 01:42:46 +00:00
|
|
|
{
|
|
|
|
compileScript = let
|
|
|
|
filename = lib.last (builtins.split "/" name);
|
|
|
|
in ''
|
|
|
|
cp $contentPath ${filename}.hs
|
|
|
|
${
|
|
|
|
lib.concatStringsSep " "
|
|
|
|
(lib.mapAttrsToList (key: val: ''${key}="${val}"'') ghcEnv)
|
|
|
|
} ${ghc.withPackages (_: libraries)}/bin/ghc ${
|
|
|
|
lib.escapeShellArgs ghcArgs
|
|
|
|
} ${filename}.hs
|
|
|
|
mv ${filename} $out
|
|
|
|
${pkgs.binutils-unwrapped}/bin/strip --strip-unneeded "$out"
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
name;
|
2021-01-04 18:20:00 +00:00
|
|
|
|
|
|
|
# writeHaskellBin takes the same arguments as writeHaskell but outputs a directory (like writeScriptBin)
|
|
|
|
writeHaskellBin = name: pkgs.writeHaskell "/bin/${name}";
|
2022-03-08 01:42:46 +00:00
|
|
|
writeHaskellScript = {
|
|
|
|
name ? "haskell-script",
|
|
|
|
bins ? [],
|
|
|
|
imports ? [],
|
|
|
|
}: code:
|
2021-05-18 14:33:28 +00:00
|
|
|
pkgs.writeHaskellBin name
|
2022-03-08 01:42:46 +00:00
|
|
|
{
|
|
|
|
ghcArgs = [
|
|
|
|
"-threaded"
|
|
|
|
"-Wall"
|
|
|
|
"-Wno-unused-top-binds"
|
|
|
|
"-Wno-missing-signatures"
|
|
|
|
"-Wno-type-defaults"
|
|
|
|
"-Wno-unused-imports"
|
|
|
|
"-Werror"
|
|
|
|
];
|
|
|
|
libraries = builtins.attrValues pkgs.myHaskellScriptPackages;
|
|
|
|
} ''
|
2020-05-27 13:20:08 +00:00
|
|
|
{-# LANGUAGE DeriveDataTypeable #-}
|
2022-01-27 23:35:56 +00:00
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
|
|
{-# LANGUAGE DeriveAnyClass #-}
|
2020-05-27 13:20:08 +00:00
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE ExtendedDefaultRules #-}
|
|
|
|
{-# LANGUAGE MultiWayIf #-}
|
|
|
|
{-# LANGUAGE LambdaCase #-}
|
|
|
|
{-# LANGUAGE ViewPatterns #-}
|
|
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
|
|
|
{-# LANGUAGE NoImplicitPrelude #-}
|
|
|
|
{-# LANGUAGE TupleSections #-}
|
2020-10-19 13:32:40 +00:00
|
|
|
{-# LANGUAGE PartialTypeSignatures #-}
|
2022-02-20 15:58:23 +00:00
|
|
|
{-# LANGUAGE BlockArguments #-}
|
2023-01-16 02:57:11 +00:00
|
|
|
{-# LANGUAGE ImportQualifiedPost #-}
|
2020-05-27 13:20:08 +00:00
|
|
|
|
|
|
|
import Shh
|
|
|
|
import Relude
|
|
|
|
import Say
|
|
|
|
import qualified Relude.Unsafe as Unsafe
|
|
|
|
import qualified Data.ByteString.Lazy as LBS
|
|
|
|
import qualified Data.ByteString as BS
|
|
|
|
import qualified Data.Text as Text
|
2022-05-31 22:52:49 +00:00
|
|
|
import System.Environment (setEnv)
|
2020-05-27 13:20:08 +00:00
|
|
|
import Control.Exception (bracket, try)
|
|
|
|
import Data.String.Interpolate (i)
|
|
|
|
import Control.Concurrent.Async
|
|
|
|
${builtins.concatStringsSep "\n" (map (x: "import ${x}") imports)}
|
|
|
|
|
|
|
|
-- Load binaries from Nix packages. The dependencies will be captured
|
|
|
|
-- in the closure.
|
|
|
|
loadFromBins (${
|
2022-03-08 06:03:20 +00:00
|
|
|
pkgs.haskellList
|
|
|
|
(builtins.map toString (bins ++ [pkgs.coreutils pkgs.nix]))
|
2020-05-27 13:20:08 +00:00
|
|
|
} :: [String])
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
${code}
|
|
|
|
'';
|
|
|
|
}
|