IHaskell/release.nix

81 lines
3.5 KiB
Nix
Raw Normal View History

2018-03-07 13:46:48 +08:00
{ compiler ? "ghc802", nixpkgs ? import <nixpkgs> {}, packages ? (_: []), rtsopts ? "-M3g -N2", systemPackages ? (_: []) }:
2017-07-10 00:19:17 +08:00
let
2017-10-12 13:56:39 +08:00
inherit (builtins) any elem filterSource listToAttrs;
lib = nixpkgs.lib;
2017-10-02 00:02:16 +08:00
cleanSource = name: type: let
2017-10-12 13:56:39 +08:00
baseName = baseNameOf (toString name);
in lib.cleanSourceFilter name type && !(
(type == "directory" && (elem baseName [ ".stack-work" "dist"])) ||
2017-10-16 23:41:34 +08:00
any (lib.flip lib.hasSuffix baseName) [ ".hi" ".ipynb" ".nix" ".sock" ".yaml" ".yml" ]
2017-10-12 13:56:39 +08:00
);
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" "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;
2017-10-12 13:56:39 +08:00
displays = self: listToAttrs (
2017-07-10 00:19:17 +08:00
map
(display: { name = display; value = self.callCabal2nix display "${ihaskell-display-src}/${display}" {}; })
2017-07-10 00:19:17 +08:00
[
"ihaskell-aeson"
"ihaskell-blaze"
"ihaskell-charts"
"ihaskell-diagrams"
"ihaskell-gnuplot"
"ihaskell-hatex"
"ihaskell-juicypixels"
"ihaskell-magic"
"ihaskell-plot"
"ihaskell-rlangqq"
"ihaskell-static-canvas"
"ihaskell-widgets"
]);
2018-03-07 13:46:48 +08:00
haskellPackages = nixpkgs.haskell.packages."${compiler}".override {
2017-07-10 00:19:17 +08:00
overrides = self: super: {
2018-03-07 13:46:48 +08:00
ihaskell = nixpkgs.haskell.lib.overrideCabal (
self.callCabal2nix "ihaskell" ihaskell-src {}) (_drv: {
preCheck = ''
export HOME=$(${nixpkgs.pkgs.coreutils}/bin/mktemp -d)
export PATH=$PWD/dist/build/ihaskell:$PATH
export GHC_PACKAGE_PATH=$PWD/dist/package.conf.inplace/:$GHC_PACKAGE_PATH
2017-09-04 23:07:18 +08:00
'';
});
2018-03-07 13:46:48 +08:00
ghc-parser = self.callCabal2nix "ghc-parser" ghc-parser-src {};
ipython-kernel = self.callCabal2nix "ipython-kernel" ipython-kernel-src {};
haskell-src-exts = self.haskell-src-exts_1_20_2;
2018-03-07 13:46:48 +08:00
static-canvas = nixpkgs.haskell.lib.doJailbreak super.static-canvas;
2017-07-10 00:19:17 +08:00
} // displays self;
};
ihaskellEnv = haskellPackages.ghcWithPackages (self: [ self.ihaskell ] ++ packages self);
jupyter = nixpkgs.python3.withPackages (ps: [ ps.jupyter ps.notebook ]);
ihaskellSh = cmd: extraArgs: nixpkgs.writeScriptBin "ihaskell-${cmd}" ''
2017-10-12 12:16:30 +08:00
#! ${nixpkgs.stdenv.shell}
2017-07-10 00:19:17 +08:00
export GHC_PACKAGE_PATH="$(echo ${ihaskellEnv}/lib/*/package.conf.d| tr ' ' ':'):$GHC_PACKAGE_PATH"
export PATH="${nixpkgs.stdenv.lib.makeBinPath ([ ihaskellEnv jupyter ] ++ systemPackages nixpkgs)}"
${ihaskellEnv}/bin/ihaskell install -l $(${ihaskellEnv}/bin/ghc --print-libdir) --use-rtsopts="${rtsopts}" && ${jupyter}/bin/jupyter ${cmd} ${extraArgs} "$@"
'';
2017-07-10 00:19:17 +08:00
in
2017-10-12 12:16:30 +08:00
nixpkgs.buildEnv {
2017-07-10 00:19:17 +08:00
name = "ihaskell-with-packages";
2017-10-12 12:16:30 +08:00
buildInputs = [ nixpkgs.makeWrapper ];
2017-07-10 00:19:17 +08:00
paths = [ ihaskellEnv jupyter ];
postBuild = ''
ln -s ${ihaskellSh "notebook" ""}/bin/ihaskell-notebook $out/bin/
ln -s ${ihaskellSh "nbconvert" ""}/bin/ihaskell-nbconvert $out/bin/
ln -s ${ihaskellSh "console" "--kernel=haskell"}/bin/ihaskell-console $out/bin/
2017-07-10 00:19:17 +08:00
for prg in $out/bin"/"*;do
2017-10-02 00:01:37 +08:00
if [[ -f $prg && -x $prg ]]; then
wrapProgram $prg --set PYTHONPATH "$(echo ${jupyter}/lib/*/site-packages)"
fi
2017-07-10 00:19:17 +08:00
done
'';
}