on e94de40 help sign in
haskell.nix/lib/ghcjs-project.nix
131 lines 5.3 kB history raw
1# For the time being we can't really treat ghcjs like a
2# regular ghc (with different target). We need this as a
3# stop-gap measure until ghcjs can be treated like a regular
4# ghc.
5#
6# `haskell-nix.ghcjsProject` wraps `haskell-nix.cabalProject'`
7# for use with the ghcjs source. It is exposed to allow GHCJS
8# developers to work on the GHCJS code in a nix-shell with
9# `shellFor`. It takes thes the clean src (from fetched
10# source or local source that has been cleaned with cleanGit.
11# It configures the source and passes it onto `cabalProject`
12# along with the necessary modules.
14# It also adds `configureInputs` and `bootInputs` that a
15# needed for configuring the source and booting the compiler
16# once it is built. These are added to the `hsPkgs.shellFor`
17# of the project.
18{ pkgs }:
19{ src
20, ghc ? pkgs.ghc
21, ghcjsVersion ? "8.6.0.1" # TODO get this from the source?
22, ghcVersion ? "8.6.5" # TODO get this from the ghc arg?
23, happy ? pkgs.haskellPackages.happy
24, alex ? pkgs.haskellPackages.alex
25, cabal-install ? pkgs.cabal-install
26, ...
27}@args:
28let
29 # Inputs needed to configure the GHCJS source tree
30 configureInputs = with pkgs; [
31 perl
32 autoconf
33 automake
34 python3
35 ] ++ [
36 ghc
37 happy
38 alex
39 cabal-install
40 ];
41 # Inputs needed to boot the GHCJS compiler
42 bootInputs = with pkgs; [
43 nodejs
44 makeWrapper
45 xorg.lndir
46 gmp
47 pkgconfig
48 ]
49 ++ [ ghc cabal-install ]
50 ++ lib.optionals stdenv.isDarwin [
51 pkgs.buildPackages.gcc # https://github.com/ghcjs/ghcjs/issues/663
52 ];
53 # Configured the GHCJS source
54 configured-src = pkgs.runCommand "configured-ghcjs-src" {
55 buildInputs = configureInputs;
56 inherit src;
57 } ''
58 export HOME=$(pwd)
59 mkdir $HOME/.cabal
60 touch $HOME/.cabal/config
61 cp -r "$src" "$out"
62 chmod -R +w "$out"
63 cd "$out"
65 # TODO: Find a better way to avoid impure version numbers
66 sed -i 's/RELEASE=NO/RELEASE=YES/' ghc/configure.ac
67 sed -i 's/${ghcjsVersion}/${ghcVersion}/' ghcjs.cabal
69 # TODO: How to actually fix this?
70 # Seems to work fine and produce the right files.
71 touch ghc/includes/ghcautoconf.h
72 mkdir -p ghc/compiler/vectorise
73 mkdir -p ghc/utils/haddock/haddock-library/vendor
75 patchShebangs .
76 sed -i 's/gcc /cc /g' utils/makePackages.sh
77 cat utils/makePackages.sh
78 ./utils/makePackages.sh copy
80 echo " build-tool-depends: alex:alex, happy:happy <= 1.19.9" >> lib/ghc-api-ghcjs/ghc-api-ghcjs.cabal
82 # nuke the HsBaseConfig.h from base.buildinfo.in; this will
83 # prevent it from being installed and provide incorrect values.
84 sed -i 's/HsBaseConfig.h//g' lib/boot/pkg/base/base.buildinfo.in
85 cat lib/boot/pkg/base/base.buildinfo.in
86 '';
87 # see https://github.com/ghcjs/ghcjs/issues/751 for the happy upper bound.
89 ghcjsProject = pkgs.haskell-nix.cabalProject' (
90 (pkgs.lib.filterAttrs
91 (n: _: builtins.any (x: x == n)
92 ["src" "ghcjsVersion" "ghcVersion" "happy" "alex" "cabal-install"]) args) // {
93 src = configured-src;
94 modules = [
95 {
96 # we need ghc-boot in here for ghcjs.
97 nonReinstallablePkgs = [ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
98 "deepseq" "array" "ghc-boot-th" "pretty" "template-haskell"
99 "ghc-boot" "binary" "bytestring" "filepath" "directory" "containers"
100 "time" "unix" "Win32" ];
101 }
102 {
103 packages.Cabal.patches = [ ./../overlays/patches/Cabal/fix-data-dir.patch ];
104 packages.ghcjs.doHaddock = false;
105 packages.haddock-ghcjs.doHaddock = false;
106 packages.haddock-api-ghcjs.doHaddock = false;
107 packages.ghcjs.flags.no-wrapper-install = true;
108 # set use-host-template-haskell. This *does*
109 # work as we use a patched ghc to boot anyway.
110 # (we apply https://github.com/ghcjs/ghc/commit/2918d88d4ef786b5f2801f6f77ac333cc56dde75 already)
111 packages.ghcjs.flags.use-host-template-haskell = true;
112 packages.ghc-api-ghcjs.flags.use-host-template-haskell = true;
113 packages.ghcjs-th.flags.use-host-template-haskell = true;
114 packages.ghc.flags.ghci = true;
115 packages.ghci.flags.ghci = true;
116 # packages.ghcjs.components.library.configureFlags = [ "-fno-wrapper-install" ];
117 }
118 ];
119 });
120in ghcjsProject // {
121 # Add `configureInputs` and `bootInputs` to the shell
122 hsPkgs = ghcjsProject.hsPkgs // {
123 # Shell suitable for configuring and building a local copy of GHCJS
124 shellFor = args: (ghcjsProject.hsPkgs.shellFor args).overrideAttrs (drv: {
125 buildInputs = (drv.buildInputs or []) ++ configureInputs;
126 nativeBuildInputs = (drv.nativeBuildInputs or []) ++ bootInputs;
127 });
128 };
129 inherit configureInputs bootInputs configured-src;