Unverified Commit cf29b2c5 authored by Vaibhav Sagar's avatar Vaibhav Sagar Committed by GitHub

release.nix: construct kernel.json manually, obviating the need for ihaskell wrappers (#1277)

parent 119655f9
......@@ -50,5 +50,5 @@ jobs:
nix-shell \
-I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/nixos-21.05 \
-p jq --run \
'test/acceptance.nbconvert.sh result/bin/ihaskell-nbconvert'
'test/acceptance.nbconvert.sh result/bin/jupyter nbconvert'
......@@ -156,7 +156,7 @@ notebook environment with one command. For example:
```bash
$ nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-20.03.tar.gz release.nix --argstr compiler ghc865 --arg packages "haskellPackages: [ haskellPackages.lens ]"
<result path>
$ <result path>/bin/ihaskell-notebook
$ <result path>/bin/jupyter notebook
```
It might take a while the first time, but subsequent builds will be much
......
{ compiler ? "ghc8104"
, jupyterlabAppDir ? null
, nixpkgs ? import <nixpkgs> {}
, packages ? (_: [])
, pythonPackages ? (_: [])
, rtsopts ? "-M3g -N2"
, systemPackages ? (_: [])
}:
import (./release.nix) { inherit compiler jupyterlabAppDir nixpkgs packages pythonPackages rtsopts systemPackages; }
import (./release.nix) { inherit compiler nixpkgs packages pythonPackages rtsopts systemPackages; }
......@@ -5,11 +5,10 @@ let
};
in
{ compiler ? "ghc901"
, jupyterlabAppDir ? null
, nixpkgs ? import nixpkgs-src {}
, packages ? (_: [])
, pythonPackages ? (_: [])
, rtsopts ? "-M3g -N2"
, systemPackages ? (_: [])
}:
import (./release.nix) { inherit compiler jupyterlabAppDir nixpkgs packages pythonPackages rtsopts systemPackages; }
import (./release.nix) { inherit compiler nixpkgs packages pythonPackages rtsopts systemPackages; }
{ compiler
, jupyterlabAppDir ? null
, nixpkgs ? import <nixpkgs> {}
, packages ? (_: [])
, pythonPackages ? (_: [])
......@@ -59,34 +58,64 @@ let
exec ${ihaskellEnv}/bin/ihaskell "$@"
'';
ihaskellJupyterCmdSh = cmd: extraArgs: nixpkgs.writeShellScriptBin "ihaskell-${cmd}" ''
export PATH="${nixpkgs.lib.makeBinPath ([ ihaskellEnv jupyterlab ] ++ systemPackages nixpkgs)}''${PATH:+:}$PATH"
export JUPYTER_DATA_DIR=$(mktemp -d) # Install IHaskell kernel and extension files to a fresh directory
${ihaskellEnv}/bin/ihaskell install \
-l $(${ihaskellEnv}/bin/ghc --print-libdir) \
--use-rtsopts="${rtsopts}" \
&& ${jupyterlab}/bin/jupyter ${cmd} ${extraArgs} "$@"
ihaskellGhcLib = nixpkgs.writeShellScriptBin "ihaskell" ''
${haskellPackages.ihaskell}/bin/ihaskell -l $(${ihaskellEnv}/bin/ghc --print-libdir) "$@"
'';
kernelFile = {
display_name = "Haskell";
argv = [
"${ihaskellGhcLib}/bin/ihaskell"
"kernel"
"{connection_file}"
"+RTS"
] ++ (nixpkgs.lib.splitString " " rtsopts) ++ [
"-RTS"
];
language = "haskell";
};
ihaskellKernelSpec = nixpkgs.runCommand "ihaskell-kernel" {} ''
export kerneldir=$out/kernels/haskell
mkdir -p $kerneldir
cp ${./html}/* $kerneldir
echo '${builtins.toJSON kernelFile}' > $kerneldir/kernel.json
'';
appDir = if jupyterlabAppDir != null
then "--app-dir=${jupyterlabAppDir}"
else "";
ihaskellLabextension = nixpkgs.runCommand "ihaskell-labextension" {} ''
export labextensiondir=$out/labextensions/jupyterlab-ihaskell
mkdir -p $labextensiondir
cp -R ${./jupyterlab-ihaskell/labextension}/* $labextensiondir
'';
ihaskellDataDir = nixpkgs.buildEnv {
name = "ihaskell-data-dir";
paths = [ ihaskellKernelSpec ihaskellLabextension ];
};
in
nixpkgs.buildEnv {
name = "ihaskell-with-packages";
buildInputs = [ nixpkgs.makeWrapper ];
paths = [ ihaskellEnv jupyterlab ];
postBuild = ''
ln -s ${ihaskellJupyterCmdSh "lab" appDir}/bin/ihaskell-lab $out/bin/
ln -s ${ihaskellJupyterCmdSh "notebook" ""}/bin/ihaskell-notebook $out/bin/
ln -s ${ihaskellJupyterCmdSh "nbconvert" ""}/bin/ihaskell-nbconvert $out/bin/
ln -s ${ihaskellJupyterCmdSh "console" "--kernel=haskell"}/bin/ihaskell-console $out/bin/
for prg in $out/bin"/"*;do
if [[ -f $prg && -x $prg ]]; then
wrapProgram $prg \
--prefix PATH : "${nixpkgs.lib.makeBinPath ([ihaskellEnv] ++ systemPackages nixpkgs)}" \
--prefix JUPYTER_PATH : "${ihaskellDataDir}"
fi
done
'';
passthru = {
inherit haskellPackages;
inherit ihaskellEnv;
inherit jupyterlab;
inherit ihaskellJupyterCmdSh;
inherit ihaskellWrapperSh;
inherit ihaskellKernelSpec;
inherit ihaskellLabextension;
inherit ihaskellDataDir;
ihaskellJsFile = ./. + "/html/kernel.js";
ihaskellLogo64 = ./. + "/html/logo-64x64.svg";
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment