1{
2 stdenv,
3 pkgsHostHost,
4 callPackage,
5 fetchgit,
6 fetchpatch,
7 ghcjsSrcJson ? null,
8 ghcjsSrc ? fetchgit (lib.importJSON ghcjsSrcJson),
9 bootPkgs,
10 stage0,
11 haskellLib,
12 cabal-install,
13 nodejs,
14 makeWrapper,
15 xorg,
16 gmp,
17 pkg-config,
18 gcc,
19 lib,
20 ghcjsDepOverrides ? (_: _: { }),
21 linkFarm,
22 buildPackages,
23}:
24
25let
26 passthru = {
27 configuredSrc = callPackage ./configured-ghcjs-src.nix {
28 inherit ghcjsSrc;
29 inherit (bootPkgs) ghc alex;
30 inherit (bootGhcjs) version;
31 happy = bootPkgs.happy_1_19_12;
32 };
33 bootPkgs = bootPkgs.extend (
34 lib.foldr lib.composeExtensions (_: _: { }) [
35 (
36 self: _:
37 import stage0 {
38 inherit (passthru) configuredSrc;
39 inherit (self) callPackage;
40 }
41 )
42
43 (callPackage ./common-overrides.nix {
44 inherit haskellLib fetchpatch buildPackages;
45 })
46 ghcjsDepOverrides
47 ]
48 );
49
50 targetPrefix = "";
51 inherit bootGhcjs;
52 inherit (bootGhcjs) version;
53 isGhcjs = true;
54
55 llvmPackages = null;
56 enableShared = true;
57
58 socket-io = pkgsHostHost.nodePackages."socket.io";
59
60 haskellCompilerName = "ghcjs-${bootGhcjs.version}";
61 };
62
63 bootGhcjs = haskellLib.justStaticExecutables passthru.bootPkgs.ghcjs;
64
65 # This provides the stuff we need from the emsdk
66 emsdk = linkFarm "emsdk" [
67 {
68 name = "upstream/bin";
69 path = buildPackages.clang + "/bin";
70 }
71 {
72 name = "upstream/emscripten";
73 path = buildPackages.emscripten + "/bin";
74 }
75 ];
76
77in
78stdenv.mkDerivation {
79 name = bootGhcjs.name;
80 src = passthru.configuredSrc;
81 nativeBuildInputs = [
82 bootGhcjs
83 passthru.bootPkgs.ghc
84 cabal-install
85 nodejs
86 makeWrapper
87 xorg.lndir
88 gmp
89 pkg-config
90 ]
91 ++ lib.optionals stdenv.hostPlatform.isDarwin [
92 gcc # https://github.com/ghcjs/ghcjs/issues/663
93 ];
94 dontConfigure = true;
95 dontInstall = true;
96
97 # Newer versions of `config.sub` reject the `js-ghcjs` host string, but the
98 # older `config.sub` filed vendored within `ghc` still works
99 dontUpdateAutotoolsGnuConfigScripts = true;
100
101 buildPhase = ''
102 export HOME=$TMP
103 mkdir $HOME/.cabal
104 touch $HOME/.cabal/config
105 cd lib/boot
106
107 export EM_CACHE="$HOME/.emscriptencache"
108 mkdir -p "$EM_CACHE"
109
110 mkdir -p $out/bin
111 mkdir -p $out/lib/${bootGhcjs.name}
112 lndir ${bootGhcjs}/bin $out/bin
113 chmod -R +w $out/bin
114 rm $out/bin/ghcjs-boot
115 cp ${bootGhcjs}/bin/ghcjs-boot $out/bin
116 rm $out/bin/haddock
117 cp ${bootGhcjs}/bin/haddock $out/bin
118 cp ${bootGhcjs}/bin/private-ghcjs-hsc2hs $out/bin/ghcjs-hsc2hs
119
120 wrapProgram $out/bin/ghcjs-boot --set ghcjs_libexecdir $out/bin
121
122 wrapProgram $out/bin/ghcjs --add-flags "-B$out/lib/${bootGhcjs.name}"
123 wrapProgram $out/bin/haddock --add-flags "-B$out/lib/${bootGhcjs.name}"
124 wrapProgram $out/bin/ghcjs-pkg --add-flags "--global-package-db=$out/lib/${bootGhcjs.name}/package.conf.d"
125 wrapProgram $out/bin/ghcjs-hsc2hs --add-flags "-I$out/lib/${bootGhcjs.name}/include --template=$out/lib/${bootGhcjs.name}/include/template-hsc.h"
126
127 env PATH=$out/bin:$PATH $out/bin/ghcjs-boot --with-emsdk=${emsdk} --no-haddock
128 '';
129
130 enableParallelBuilding = true;
131
132 inherit passthru;
133
134 meta = {
135 platforms = with lib.platforms; linux ++ darwin;
136
137 # Hydra limits jobs to only outputting 1 gigabyte worth of files.
138 # GHCJS outputs over 3 gigabytes.
139 # https://github.com/NixOS/nixpkgs/pull/137066#issuecomment-922335563
140 hydraPlatforms = lib.platforms.none;
141
142 maintainers = with lib.maintainers; [ obsidian-systems-maintenance ];
143 };
144}