1
1
mirror of https://github.com/nmattia/snack.git synced 2024-11-24 12:16:17 +03:00
snack/snack-lib/ghci.nix
Jinxuan Zhu 069f7d01fb Add Ghci options (#163)
* Add Ghci options

* Add ghci options test

* Remove Build for test
2019-11-20 20:52:14 +01:00

54 lines
1.5 KiB
Nix

{ makeWrapper, symlinkJoin, lib, callPackage, writeScriptBin }:
with (callPackage ./module-spec.nix {});
with (callPackage ./modules.nix {});
rec {
# Write a new ghci executable that loads all the modules defined in the
# module spec
ghciWithMain = ghcWith: mainModSpec:
let
imports = allTransitiveImports [mainModSpec];
modSpecs = [mainModSpec] ++ imports;
in ghciWithModules ghcWith modSpecs;
ghciWithModules = ghcWith: modSpecs:
let
ghcOpts = allTransitiveGhcOpts modSpecs
++ (map (x: "-X${x}") (allTransitiveExtensions modSpecs));
ghc = ghcWith (allTransitiveDeps modSpecs);
ghciArgs = ghcOpts ++ absoluteModuleFiles;
absoluteModuleFiles =
map
(mod:
builtins.toString (mod.moduleBase) +
"/${moduleToFile mod.moduleName}"
)
modSpecs;
dirs = allTransitiveDirectories modSpecs;
in
# This symlinks the extra dirs to $PWD for GHCi to work
writeScriptBin "ghci-with-files"
''
#!/usr/bin/env bash
set -euo pipefail
TRAPS=""
for i in ${lib.strings.escapeShellArgs dirs}; do
if [ "$i" != "$PWD" ]; then
for j in $(find "$i" ! -path "$i"); do
file=$(basename $j)
echo "Temporarily symlinking $j to $file..."
ln -s $j $file
TRAPS="rm $file ; $TRAPS"
trap "$TRAPS" EXIT
echo "done."
done
fi
done
${ghc}/bin/ghci ${lib.strings.escapeShellArgs ghciArgs} $@
'';
}