mirror of
https://github.com/IHaskell/IHaskell.git
synced 2025-04-19 04:46:08 +00:00
123 lines
4.5 KiB
Nix
123 lines
4.5 KiB
Nix
{ compiler
|
|
, nixpkgs ? import <nixpkgs> {}
|
|
, packages ? (_: [])
|
|
, pythonPackages ? (_: [])
|
|
, rtsopts ? "-M3g -N2"
|
|
, systemPackages ? (_: [])
|
|
}:
|
|
|
|
let
|
|
inherit (builtins) any elem filterSource listToAttrs;
|
|
lib = nixpkgs.lib;
|
|
cleanSource = name: type: let
|
|
baseName = baseNameOf (toString name);
|
|
in lib.cleanSourceFilter name type && !(
|
|
(type == "directory" && (elem baseName [ ".stack-work" "dist"])) ||
|
|
any (lib.flip lib.hasSuffix baseName) [ ".hi" ".ipynb" ".nix" ".sock" ".yaml" ".yml" ]
|
|
);
|
|
ihaskellSourceFilter = src: name: type: let
|
|
relPath = lib.removePrefix (toString src + "/") (toString name);
|
|
in cleanSource name type && ( any (lib.flip lib.hasPrefix relPath) [
|
|
"src" "main" "html" "jupyterlab-ihaskell" "Setup.hs" "ihaskell.cabal" "LICENSE"
|
|
]);
|
|
ihaskell-src = filterSource (ihaskellSourceFilter ./.) ./.;
|
|
ipython-kernel-src = filterSource cleanSource ./ipython-kernel;
|
|
ghc-parser-src = filterSource cleanSource ./ghc-parser;
|
|
ihaskell-display-src = filterSource cleanSource ./ihaskell-display;
|
|
displays = self: listToAttrs (
|
|
map
|
|
(display: { name = "ihaskell-${display}"; value = self.callCabal2nix display "${ihaskell-display-src}/ihaskell-${display}" {}; })
|
|
[ "aeson" "blaze" "charts" "diagrams" "gnuplot" "graphviz" "hatex" "juicypixels" "magic" "plot" "rlangqq" "static-canvas" "widgets" ]);
|
|
haskellPackages = nixpkgs.haskell.packages."${compiler}".override (old: {
|
|
overrides = nixpkgs.lib.composeExtensions (old.overrides or (_: _: {})) (self: super: {
|
|
ihaskell = nixpkgs.haskell.lib.overrideCabal (
|
|
self.callCabal2nix "ihaskell" ihaskell-src {}) (drv: {
|
|
preCheck = ''
|
|
export HOME=$TMPDIR/home
|
|
export PATH=$PWD/dist/build/ihaskell:$PATH
|
|
export GHC_PACKAGE_PATH=$PWD/dist/package.conf.inplace/:$GHC_PACKAGE_PATH
|
|
'';
|
|
configureFlags = (drv.configureFlags or []) ++ [
|
|
# otherwise the tests are agonisingly slow and the kernel times out
|
|
"--enable-executable-dynamic"
|
|
];
|
|
doHaddock = false;
|
|
});
|
|
ghc-parser = self.callCabal2nix "ghc-parser" ghc-parser-src {};
|
|
ipython-kernel = self.callCabal2nix "ipython-kernel" ipython-kernel-src {};
|
|
|
|
inline-r = nixpkgs.haskell.lib.dontCheck super.inline-r;
|
|
static-canvas = nixpkgs.haskell.lib.doJailbreak super.static-canvas;
|
|
} // displays self);
|
|
});
|
|
ihaskellEnv = haskellPackages.ghcWithPackages packages;
|
|
jupyterlab = nixpkgs.python3.withPackages (ps: [ ps.jupyterlab ] ++ pythonPackages ps);
|
|
|
|
ihaskellWrapperSh = nixpkgs.writeShellScriptBin "ihaskell-wrapper" ''
|
|
export PATH="${nixpkgs.lib.makeBinPath ([ ihaskellEnv jupyterlab ] ++ systemPackages nixpkgs)}''${PATH:+:}$PATH"
|
|
exec ${haskellPackages.ihaskell}/bin/ihaskell "$@"
|
|
'';
|
|
|
|
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
|
|
'';
|
|
|
|
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 = ''
|
|
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 ihaskellWrapperSh;
|
|
inherit ihaskellKernelSpec;
|
|
inherit ihaskellLabextension;
|
|
inherit ihaskellDataDir;
|
|
ihaskellJsFile = ./. + "/html/kernel.js";
|
|
ihaskellLogo64 = ./. + "/html/logo-64x64.svg";
|
|
};
|
|
}
|