-
Notifications
You must be signed in to change notification settings - Fork 9
/
cross-js.nix
102 lines (98 loc) · 4.43 KB
/
cross-js.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{ self, pkgs, compiler, compiler-nix-name, toolsModule, withHLS ? true, withHlint ? true, withIOG ? true }:
let tool-version-map = import ./tool-map.nix;
tool = tool-name: pkgs.haskell-nix.tool compiler-nix-name tool-name [(tool-version-map compiler-nix-name tool-name) toolsModule];
cabal-install = pkgs.haskell-nix.nix-tools-unchecked.exes.cabal;
# add a trace helper. This will trace a message about disabling a component despite requesting it, if it's not supported in that compiler.
compiler-not-in = compiler-list: name: (if __elem compiler-nix-name compiler-list then __trace "No ${name}. Not yet compatible with ${compiler-nix-name}" false else true);
# * wrapped tools:
# A cabal-install wrapper that sets the appropriate static flags
wrapped-cabal = pkgs.writeShellApplication {
name = "cabal";
runtimeInputs = [ cabal-install pkgs.curl ];
text = with pkgs; ''
# We do not want to quote NIX_CABAL_FLAGS
# it will leave an empty argument, if they are empty.
# shellcheck disable=SC2086
case "$1" in
build)
cabal \
"$@" \
$NIX_CABAL_FLAGS
;;
clean|unpack)
cabal "$@"
;;
*)
cabal $NIX_CABAL_FLAGS "$@"
;;
esac
'';
};
wrapped-hsc2hs = pkgs.pkgsBuildBuild.writeShellApplication {
name = "${compiler.targetPrefix}hsc2hs";
text = ''
${compiler}/bin/${compiler.targetPrefix}hsc2hs --cross-compile "$@"
'';
};
quirks = (import ./quirks.nix { inherit pkgs; });
in
pkgs.mkShell ({
# Note [cabal override]:
#
# We need to override the `cabal` command and pass --ghc-options for the
# libraries. This is fairly annoying, but necessary, as ghc will otherwise
# pick up the dynamic libraries, instead of the static ones.
#
# Note [static gmp]:
#
# We can only link GMP statically, because the thing we are linking is fully
# open source, and licenses accordingly. Otherwise we'd have to link gmp
# dynamically. This requirement will be gone with gmp-bignum.
#
NIX_CABAL_FLAGS = [
"--with-ghc=javascript-unknown-ghcjs-ghc"
"--with-ghc-pkg=javascript-unknown-ghcjs-ghc-pkg"
"--with-hsc2hs=javascript-unknown-ghcjs-hsc2hs"
# ensure that the linker knows we want a static build product
# "--enable-executable-static"
];
# hardeningDisable = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isMusl [ "format" "pie" ];
inherit (quirks) CABAL_PROJECT_LOCAL_TEMPLATE;
shellHook =
with pkgs;
let flavor = "${compiler-nix-name}-js"
+ lib.optionalString (!withHLS && !withHlint) "-minimal"
+ lib.optionalString withIOG "-iog"
;
in ''
export PS1="\[\033[01;33m\][\w]$\[\033[00m\] "
${figlet}/bin/figlet -f rectangles 'IOG Haskell Shell'
${figlet}/bin/figlet -f small "*= JS edition =*"
echo "Revision (input-output-hk/devx): ${if self ? rev then self.rev else "unknown/dirty checkout"}."
export CABAL_DIR=$HOME/.cabal-js
echo "CABAL_DIR set to $CABAL_DIR"
echo ""
'' + (quirks.hint flavor) + quirks.shellHook;
buildInputs = [];
nativeBuildInputs = [ wrapped-hsc2hs wrapped-cabal compiler ] ++ (with pkgs; [
nodejs # helpful to evaluate output on the commandline.
cabal-install
(pkgs.pkg-config or pkgconfig)
(tool "happy")
(tool "alex")
stdenv.cc.cc.lib ]) ++ (with pkgs.buildPackages; [
])
++ pkgs.lib.optional (withHLS && (compiler-not-in (
# it appears we can't get HLS build with 9.8 yet.
pkgs.lib.optional (builtins.compareVersions compiler.version "9.7" >= 0) compiler-nix-name
++ pkgs.lib.optional (pkgs.stdenv.hostPlatform.isDarwin && pkgs.stdenv.hostPlatform.isAarch64) "ghc902") "Haskell Language Server")) (tool "haskell-language-server")
++ pkgs.lib.optional (withHlint && (compiler-not-in (
pkgs.lib.optional (builtins.compareVersions compiler.version "9.8" >= 0) compiler-nix-name
++ pkgs.lib.optional (pkgs.stdenv.hostPlatform.isDarwin && pkgs.stdenv.hostPlatform.isAarch64) "ghc902") "HLint")) (tool "hlint")
++ pkgs.lib.optional withIOG
(with pkgs; [ cddl cbor-diag ]
++ map pkgs.lib.getDev (with pkgs; [
libblst libsodium-vrf secp256k1
]))
;
})