summaryrefslogtreecommitdiff
path: root/pkgs/development/tools/haskell/ihaskell/wrapper.nix
blob: f1c947d83097e10217c273294d7f3a073c1e0cc7 (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
{
  lib,
  stdenv,
  writeScriptBin,
  makeWrapper,
  buildEnv,
  ghcWithPackages,
  jupyter,
  packages,
}:
let
  ihaskellEnv = ghcWithPackages (
    self:
    [
      self.ihaskell
      self.ihaskell-blaze
      self.ihaskell-diagrams
    ]
    ++ packages self
  );
  ihaskellSh = writeScriptBin "ihaskell-notebook" ''
    #! ${stdenv.shell}
    export GHC_PACKAGE_PATH="$(${ihaskellEnv}/bin/ghc --print-global-package-db):$GHC_PACKAGE_PATH"
    export PATH="${
      lib.makeBinPath [
        ihaskellEnv
        jupyter
      ]
    }''${PATH:+:}$PATH"
    ${ihaskellEnv}/bin/ihaskell install -l $(${ihaskellEnv}/bin/ghc --print-libdir) && ${jupyter}/bin/jupyter notebook
  '';
in
buildEnv {
  name = "ihaskell-with-packages";
  nativeBuildInputs = [ makeWrapper ];
  paths = [
    ihaskellEnv
    jupyter
  ];
  postBuild = ''
    ln -s ${ihaskellSh}/bin/ihaskell-notebook $out/bin/
    for prg in $out/bin"/"*;do
      if [[ -f $prg && -x $prg ]]; then
        wrapProgram $prg --set PYTHONPATH "$(echo ${jupyter}/lib/*/site-packages)"
      fi
    done
  '';
}