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: ...@@ -50,5 +50,5 @@ jobs:
nix-shell \ nix-shell \
-I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/nixos-21.05 \ -I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/nixos-21.05 \
-p jq --run \ -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: ...@@ -156,7 +156,7 @@ notebook environment with one command. For example:
```bash ```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 ]" $ 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>
$ <result path>/bin/ihaskell-notebook $ <result path>/bin/jupyter notebook
``` ```
It might take a while the first time, but subsequent builds will be much It might take a while the first time, but subsequent builds will be much
......
{ compiler ? "ghc8104" { compiler ? "ghc8104"
, jupyterlabAppDir ? null
, nixpkgs ? import <nixpkgs> {} , nixpkgs ? import <nixpkgs> {}
, packages ? (_: []) , packages ? (_: [])
, pythonPackages ? (_: []) , pythonPackages ? (_: [])
, rtsopts ? "-M3g -N2" , rtsopts ? "-M3g -N2"
, systemPackages ? (_: []) , 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 ...@@ -5,11 +5,10 @@ let
}; };
in in
{ compiler ? "ghc901" { compiler ? "ghc901"
, jupyterlabAppDir ? null
, nixpkgs ? import nixpkgs-src {} , nixpkgs ? import nixpkgs-src {}
, packages ? (_: []) , packages ? (_: [])
, pythonPackages ? (_: []) , pythonPackages ? (_: [])
, rtsopts ? "-M3g -N2" , rtsopts ? "-M3g -N2"
, systemPackages ? (_: []) , systemPackages ? (_: [])
}: }:
import (./release.nix) { inherit compiler jupyterlabAppDir nixpkgs packages pythonPackages rtsopts systemPackages; } import (./release.nix) { inherit compiler nixpkgs packages pythonPackages rtsopts systemPackages; }
{ compiler { compiler
, jupyterlabAppDir ? null
, nixpkgs ? import <nixpkgs> {} , nixpkgs ? import <nixpkgs> {}
, packages ? (_: []) , packages ? (_: [])
, pythonPackages ? (_: []) , pythonPackages ? (_: [])
...@@ -59,34 +58,64 @@ let ...@@ -59,34 +58,64 @@ let
exec ${ihaskellEnv}/bin/ihaskell "$@" exec ${ihaskellEnv}/bin/ihaskell "$@"
''; '';
ihaskellJupyterCmdSh = cmd: extraArgs: nixpkgs.writeShellScriptBin "ihaskell-${cmd}" '' ihaskellGhcLib = nixpkgs.writeShellScriptBin "ihaskell" ''
export PATH="${nixpkgs.lib.makeBinPath ([ ihaskellEnv jupyterlab ] ++ systemPackages nixpkgs)}''${PATH:+:}$PATH" ${haskellPackages.ihaskell}/bin/ihaskell -l $(${ihaskellEnv}/bin/ghc --print-libdir) "$@"
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) \ kernelFile = {
--use-rtsopts="${rtsopts}" \ display_name = "Haskell";
&& ${jupyterlab}/bin/jupyter ${cmd} ${extraArgs} "$@" 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}" ihaskellLabextension = nixpkgs.runCommand "ihaskell-labextension" {} ''
else ""; 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 in
nixpkgs.buildEnv { nixpkgs.buildEnv {
name = "ihaskell-with-packages"; name = "ihaskell-with-packages";
buildInputs = [ nixpkgs.makeWrapper ];
paths = [ ihaskellEnv jupyterlab ]; paths = [ ihaskellEnv jupyterlab ];
postBuild = '' postBuild = ''
ln -s ${ihaskellJupyterCmdSh "lab" appDir}/bin/ihaskell-lab $out/bin/ for prg in $out/bin"/"*;do
ln -s ${ihaskellJupyterCmdSh "notebook" ""}/bin/ihaskell-notebook $out/bin/ if [[ -f $prg && -x $prg ]]; then
ln -s ${ihaskellJupyterCmdSh "nbconvert" ""}/bin/ihaskell-nbconvert $out/bin/ wrapProgram $prg \
ln -s ${ihaskellJupyterCmdSh "console" "--kernel=haskell"}/bin/ihaskell-console $out/bin/ --prefix PATH : "${nixpkgs.lib.makeBinPath ([ihaskellEnv] ++ systemPackages nixpkgs)}" \
--prefix JUPYTER_PATH : "${ihaskellDataDir}"
fi
done
''; '';
passthru = { passthru = {
inherit haskellPackages; inherit haskellPackages;
inherit ihaskellEnv; inherit ihaskellEnv;
inherit jupyterlab; inherit jupyterlab;
inherit ihaskellJupyterCmdSh;
inherit ihaskellWrapperSh; inherit ihaskellWrapperSh;
inherit ihaskellKernelSpec;
inherit ihaskellLabextension;
inherit ihaskellDataDir;
ihaskellJsFile = ./. + "/html/kernel.js"; ihaskellJsFile = ./. + "/html/kernel.js";
ihaskellLogo64 = ./. + "/html/logo-64x64.svg"; 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