blob: 50b496bb7b41e0e4874e5e28661d33d48687bdfe (
plain)
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
|
{
lib,
runCommand,
runtimeShell,
writeShellScript,
}:
{
microhs,
packages,
}:
let
packages' = [ microhs ] ++ lib.filter (p: p != null) packages;
extraFlags = lib.concatMapStringsSep " " (
p: "-a${p}/lib/mcabal/${microhs.haskellCompilerName}"
) packages';
wrapper = writeShellScript "mhs-wrapper" ''
args=("$@")
noExtra=0
for ((i=0; i<"''${#args[@]}"; ++i)); do
case "''${args[i]}" in
--version | --numeric-version)
noExtra=1
;;
*)
;;
esac
done
if test "$noExtra" -eq 0; then
for arg in ${extraFlags}; do
args[i++]="$arg"
done
fi
if (( "''${NIX_DEBUG:-0}" >= 1 )); then
printf 'mhs-wrapper: mhs %s\n' "''${args[*]}" >&2
fi
exec ${microhs}/bin/mhs "''${args[@]}"
'';
in
runCommand "${microhs.name}-wrapped"
{
inherit (microhs) passthru;
}
''
mkdir -p $out/bin
cp -rs ${microhs}/bin/* $out/bin/
rm $out/bin/mhs 2>/dev/null || true
cp ${wrapper} $out/bin/mhs
''
|