about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/ghcjs/8.10/default.nix
blob: 78d757efee3c642ff9b95000fe5261e8f3d82c5b (plain) (blame)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{ stdenv
, pkgsHostHost
, callPackage
, fetchgit
, fetchpatch
, ghcjsSrcJson ? null
, ghcjsSrc ? fetchgit (lib.importJSON ghcjsSrcJson)
, bootPkgs
, stage0
, haskellLib
, cabal-install
, nodejs
, makeWrapper
, xorg
, gmp
, pkg-config
, gcc
, lib
, ghcjsDepOverrides ? (_:_:{})
, haskell
, linkFarm
, buildPackages
}:

let
  passthru = {
    configuredSrc = callPackage ./configured-ghcjs-src.nix {
      inherit ghcjsSrc;
      inherit (bootPkgs) ghc alex;
      inherit (bootGhcjs) version;
      happy = bootPkgs.happy_1_19_12;
    };
    bootPkgs = bootPkgs.extend (lib.foldr lib.composeExtensions (_:_:{}) [
      (self: _: import stage0 {
        inherit (passthru) configuredSrc;
        inherit (self) callPackage;
      })

      (callPackage ./common-overrides.nix {
        inherit haskellLib fetchpatch buildPackages;
      })
      ghcjsDepOverrides
    ]);

    targetPrefix = "";
    inherit bootGhcjs;
    inherit (bootGhcjs) version;
    isGhcjs = true;

    enableShared = true;

    socket-io = pkgsHostHost.nodePackages."socket.io";

    haskellCompilerName = "ghcjs-${bootGhcjs.version}";
  };

  bootGhcjs = haskellLib.justStaticExecutables passthru.bootPkgs.ghcjs;

  # This provides the stuff we need from the emsdk
  emsdk = linkFarm "emsdk" [
    { name = "upstream/bin"; path = buildPackages.clang + "/bin";}
    { name = "upstream/emscripten"; path = buildPackages.emscripten + "/bin"; }
  ];

in stdenv.mkDerivation {
    name = bootGhcjs.name;
    src = passthru.configuredSrc;
    nativeBuildInputs = [
      bootGhcjs
      passthru.bootPkgs.ghc
      cabal-install
      nodejs
      makeWrapper
      xorg.lndir
      gmp
      pkg-config
    ] ++ lib.optionals stdenv.isDarwin [
      gcc # https://github.com/ghcjs/ghcjs/issues/663
    ];
    dontConfigure = true;
    dontInstall = true;

    # Newer versions of `config.sub` reject the `js-ghcjs` host string, but the
    # older `config.sub` filed vendored within `ghc` still works
    dontUpdateAutotoolsGnuConfigScripts = true;

    buildPhase = ''
      export HOME=$TMP
      mkdir $HOME/.cabal
      touch $HOME/.cabal/config
      cd lib/boot

      mkdir -p $out/bin
      mkdir -p $out/lib/${bootGhcjs.name}
      lndir ${bootGhcjs}/bin $out/bin
      chmod -R +w $out/bin
      rm $out/bin/ghcjs-boot
      cp ${bootGhcjs}/bin/ghcjs-boot $out/bin
      rm $out/bin/haddock
      cp ${bootGhcjs}/bin/haddock $out/bin
      cp ${bootGhcjs}/bin/private-ghcjs-hsc2hs $out/bin/ghcjs-hsc2hs

      wrapProgram $out/bin/ghcjs-boot --set ghcjs_libexecdir $out/bin

      wrapProgram $out/bin/ghcjs --add-flags "-B$out/lib/${bootGhcjs.name}"
      wrapProgram $out/bin/haddock --add-flags "-B$out/lib/${bootGhcjs.name}"
      wrapProgram $out/bin/ghcjs-pkg --add-flags "--global-package-db=$out/lib/${bootGhcjs.name}/package.conf.d"
      wrapProgram $out/bin/ghcjs-hsc2hs --add-flags "-I$out/lib/${bootGhcjs.name}/include --template=$out/lib/${bootGhcjs.name}/include/template-hsc.h"

      env PATH=$out/bin:$PATH $out/bin/ghcjs-boot --with-emsdk=${emsdk} --no-haddock
    '';

    enableParallelBuilding = true;

    inherit passthru;

    meta = {
      platforms = with lib.platforms; linux ++ darwin;

      # Hydra limits jobs to only outputting 1 gigabyte worth of files.
      # GHCJS outputs over 3 gigabytes.
      # https://github.com/NixOS/nixpkgs/pull/137066#issuecomment-922335563
      hydraPlatforms = lib.platforms.none;

      maintainers = with lib.maintainers; [ obsidian-systems-maintenance ];
    };
  }