-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathghci.nix
53 lines (47 loc) · 1.55 KB
/
ghci.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{ 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} $@
'';
}