Merge branch 'idris-packages'

This commit is contained in:
Shea Levy 2015-11-27 13:44:06 -05:00
commit f7c2cd3347
8 changed files with 219 additions and 0 deletions

View File

@ -0,0 +1,39 @@
Idris packages
==============
This directory contains build rules for idris packages. In addition,
it contains several functions to build and compose those packages.
Everything is exposed to the user via the `idrisPackages` attribute.
callPackage
------------
This is like the normal nixpkgs callPackage function, specialized to
idris packages.
builtins
---------
This is a list of all of the libraries that come packaged with Idris
itself.
build-idris-package
--------------------
A function to build an idris package. Its sole argument is a set like
you might pass to `stdenv.mkDerivation`, except `build-idris-package`
sets several attributes for you. See `build-idris-package.nix` for
details.
build-builtin-package
----------------------
A version of `build-idris-package` specialized to builtin libraries.
Mostly for internal use.
with-packages
-------------
Bundle idris together with a list of packages. Because idris currently
only supports a single directory in its library path, you must include
all desired libraries here, including `prelude` and `base`.

View File

@ -0,0 +1,3 @@
* Build the RTS separately from Idris
* idris2nix
* Only require gmp, rts when compiling executables

View File

@ -0,0 +1,19 @@
# Build one of the packages that come with idris
# name: The name of the package
# deps: The dependencies of the package
{ idris, build-idris-package, lib }: name: deps: build-idris-package {
inherit name;
propagatedBuildInputs = deps;
inherit (idris) src;
postUnpack = ''
mv $sourceRoot/libs/${name} $IDRIS_LIBRARY_PATH
sourceRoot=$IDRIS_LIBRARY_PATH/${name}
'';
meta = idris.meta // {
description = "${name} builtin Idris library";
};
}

View File

@ -0,0 +1,40 @@
# Build an idris package
#
# args: Additional arguments to pass to mkDerivation. Generally should include at least
# name and src.
{ stdenv, idris, gmp }: args: stdenv.mkDerivation ({
preHook = ''
mkdir idris-libs
export IDRIS_LIBRARY_PATH=$PWD/idris-libs
addIdrisLibs () {
if [ -d $1/lib/${idris.name} ]; then
ln -sv $1/lib/${idris.name}/* $IDRIS_LIBRARY_PATH
fi
}
envHooks+=(addIdrisLibs)
'';
configurePhase = ''
export TARGET=$out/lib/${idris.name}
'';
buildPhase = ''
${idris}/bin/idris --build *.ipkg
'';
doCheck = true;
checkPhase = ''
if grep -q test *.ipkg; then
${idris}/bin/idris --testpkg *.ipkg
fi
'';
installPhase = ''
${idris}/bin/idris --install *.ipkg
'';
buildInputs = [ gmp ];
} // args)

View File

@ -0,0 +1,41 @@
{ pkgs, idris, overrides ? (self: super: {}) }: let
inherit (pkgs.lib) callPackageWith fix' extends;
/* Taken from haskell-modules/default.nix, should probably abstract this away */
callPackageWithScope = scope: drv: args: (callPackageWith scope drv args) // {
overrideScope = f: callPackageWithScope (mkScope (fix' (extends f scope.__unfix__))) drv args;
};
mkScope = scope : pkgs // pkgs.xorg // pkgs.gnome // scope;
idrisPackages = self: let
defaultScope = mkScope self;
callPackage = callPackageWithScope defaultScope;
builtins_ = pkgs.lib.mapAttrs self.build-builtin-package {
prelude = [];
base = [ self.prelude ];
contrib = [ self.prelude self.base ];
effects = [ self.prelude self.base ];
pruviloj = [ self.prelude self.base ];
};
files = builtins.filter (n: n != "default") (pkgs.lib.mapAttrsToList (name: type: let
m = builtins.match "(.*)\.nix" name;
in if m == null then "default" else builtins.head m) (builtins.readDir ./.));
in (builtins.listToAttrs (map (name: {
inherit name;
value = callPackage (./. + "/${name}.nix") {};
}) files)) // {
inherit idris callPackage;
# A list of all of the libraries that come with idris
builtins = pkgs.lib.mapAttrsToList (name: value: value) builtins_;
} // builtins_;
in fix' (extends overrides idrisPackages)

View File

@ -0,0 +1,46 @@
# Build a version of idris with a set of packages visible
# packages: The packages visible to idris
{ stdenv, idris }: packages: stdenv.mkDerivation {
inherit (idris) name;
buildInputs = packages;
preHook = ''
mkdir -p $out/lib/${idris.name}
installIdrisLib () {
if [ -d $1/lib/${idris.name} ]; then
ln -sv $1/lib/${idris.name}/* $out/lib/${idris.name}
fi
}
envHooks+=(installIdrisLib)
'';
unpackPhase = ''
cat >idris.c <<EOF
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int main (int argc, char ** argv) {
/* idris currently only supports a single library path, so respect it if the user set it */
setenv("IDRIS_LIBRARY_PATH", "$out/lib/${idris.name}", 0);
execv("${idris}/bin/idris", argv);
perror("executing ${idris}/bin/idris");
return 127;
}
EOF
'';
buildPhase = ''
gcc -O3 -o idris idris.c
'';
installPhase = ''
mkdir -p $out/bin
mv idris $out/bin
'';
stripAllList = [ "bin" ];
}

View File

@ -0,0 +1,27 @@
{ build-idris-package
, fetchgit
, prelude
, base
, lib
, idris
}: build-idris-package {
name = "wl-pprint";
src = fetchgit {
url = "git://github.com/shayan-najd/wl-pprint.git";
rev = "120f654b0b9838b57e10b163d3562d959439fb07";
sha256 = "b5d02a9191973dd8915279e84a9b4df430eb252f429327f45eb8a047d8bb954d";
};
propagatedBuildInputs = [ prelude base ];
meta = {
description = "Wadler-Leijen pretty-printing library";
homepage = https://github.com/shayan-najd/wl-pprint;
license = lib.licenses.bsd2;
inherit (idris.meta) platforms;
};
}

View File

@ -4121,6 +4121,10 @@ let
icedtea_web = icedtea8_web;
idrisPackages = callPackage ../development/idris-modules {
inherit (haskellPackages) idris;
};
ikarus = callPackage ../development/compilers/ikarus { };
intercal = callPackage ../development/compilers/intercal { };