git.iko.soy/typeable/nixpkgs
on master help sign in
Merge branch 'idris-packages'
commitf7c2cd33479ce2489e2b47a9a91e453aaf25a4d4 authorShea Levy <shea@shealevy.com> dateFri 27 Nov 2015, 13:44 (11 years ago) parenta8abf059562549
8 files changed+219
pkgs/development/idris-modules/README.md+39 pkgs/development/idris-modules/TODO.md+3 pkgs/development/idris-modules/build-builtin-package.nix+19 pkgs/development/idris-modules/build-idris-package.nix+40 pkgs/development/idris-modules/default.nix+41 pkgs/development/idris-modules/with-packages.nix+46 pkgs/development/idris-modules/wl-pprint.nix+27 pkgs/top-level/all-packages.nix+4
pkgs/development/idris-modules/README.mdnew file+39
@@ -0,0 +1,39 @@
1+Idris packages
2+==============
3+
4+This directory contains build rules for idris packages. In addition,
5+it contains several functions to build and compose those packages.
6+Everything is exposed to the user via the `idrisPackages` attribute.
7+
8+callPackage
9+------------
10+
11+This is like the normal nixpkgs callPackage function, specialized to
12+idris packages.
13+
14+builtins
15+---------
16+
17+This is a list of all of the libraries that come packaged with Idris
18+itself.
19+
20+build-idris-package
21+--------------------
22+
23+A function to build an idris package. Its sole argument is a set like
24+you might pass to `stdenv.mkDerivation`, except `build-idris-package`
25+sets several attributes for you. See `build-idris-package.nix` for
26+details.
27+
28+build-builtin-package
29+----------------------
30+
31+A version of `build-idris-package` specialized to builtin libraries.
32+Mostly for internal use.
33+
34+with-packages
35+-------------
36+
37+Bundle idris together with a list of packages. Because idris currently
38+only supports a single directory in its library path, you must include
39+all desired libraries here, including `prelude` and `base`.
pkgs/development/idris-modules/TODO.mdnew file+3
@@ -0,0 +1,3 @@
1+* Build the RTS separately from Idris
2+* idris2nix
3+* Only require gmp, rts when compiling executables
pkgs/development/idris-modules/build-builtin-package.nixnew file+19
@@ -0,0 +1,19 @@
1+# Build one of the packages that come with idris
2+# name: The name of the package
3+# deps: The dependencies of the package
4+{ idris, build-idris-package, lib }: name: deps: build-idris-package {
5+ inherit name;
6+
7+ propagatedBuildInputs = deps;
8+
9+ inherit (idris) src;
10+
11+ postUnpack = ''
12+ mv $sourceRoot/libs/${name} $IDRIS_LIBRARY_PATH
13+ sourceRoot=$IDRIS_LIBRARY_PATH/${name}
14+ '';
15+
16+ meta = idris.meta // {
17+ description = "${name} builtin Idris library";
18+ };
19+}
pkgs/development/idris-modules/build-idris-package.nixnew file+40
@@ -0,0 +1,40 @@
1+# Build an idris package
2+#
3+# args: Additional arguments to pass to mkDerivation. Generally should include at least
4+# name and src.
5+{ stdenv, idris, gmp }: args: stdenv.mkDerivation ({
6+ preHook = ''
7+ mkdir idris-libs
8+ export IDRIS_LIBRARY_PATH=$PWD/idris-libs
9+
10+ addIdrisLibs () {
11+ if [ -d $1/lib/${idris.name} ]; then
12+ ln -sv $1/lib/${idris.name}/* $IDRIS_LIBRARY_PATH
13+ fi
14+ }
15+
16+ envHooks+=(addIdrisLibs)
17+ '';
18+
19+ configurePhase = ''
20+ export TARGET=$out/lib/${idris.name}
21+ '';
22+
23+ buildPhase = ''
24+ ${idris}/bin/idris --build *.ipkg
25+ '';
26+
27+ doCheck = true;
28+
29+ checkPhase = ''
30+ if grep -q test *.ipkg; then
31+ ${idris}/bin/idris --testpkg *.ipkg
32+ fi
33+ '';
34+
35+ installPhase = ''
36+ ${idris}/bin/idris --install *.ipkg
37+ '';
38+
39+ buildInputs = [ gmp ];
40+} // args)
pkgs/development/idris-modules/default.nixnew file+41
@@ -0,0 +1,41 @@
1+{ pkgs, idris, overrides ? (self: super: {}) }: let
2+ inherit (pkgs.lib) callPackageWith fix' extends;
3+
4+ /* Taken from haskell-modules/default.nix, should probably abstract this away */
5+ callPackageWithScope = scope: drv: args: (callPackageWith scope drv args) // {
6+ overrideScope = f: callPackageWithScope (mkScope (fix' (extends f scope.__unfix__))) drv args;
7+ };
8+
9+ mkScope = scope : pkgs // pkgs.xorg // pkgs.gnome // scope;
10+
11+ idrisPackages = self: let
12+ defaultScope = mkScope self;
13+
14+ callPackage = callPackageWithScope defaultScope;
15+
16+ builtins_ = pkgs.lib.mapAttrs self.build-builtin-package {
17+ prelude = [];
18+
19+ base = [ self.prelude ];
20+
21+ contrib = [ self.prelude self.base ];
22+
23+ effects = [ self.prelude self.base ];
24+
25+ pruviloj = [ self.prelude self.base ];
26+ };
27+
28+ files = builtins.filter (n: n != "default") (pkgs.lib.mapAttrsToList (name: type: let
29+ m = builtins.match "(.*)\.nix" name;
30+ in if m == null then "default" else builtins.head m) (builtins.readDir ./.));
31+ in (builtins.listToAttrs (map (name: {
32+ inherit name;
33+
34+ value = callPackage (./. + "/${name}.nix") {};
35+ }) files)) // {
36+ inherit idris callPackage;
37+
38+ # A list of all of the libraries that come with idris
39+ builtins = pkgs.lib.mapAttrsToList (name: value: value) builtins_;
40+ } // builtins_;
41+in fix' (extends overrides idrisPackages)
pkgs/development/idris-modules/with-packages.nixnew file+46
@@ -0,0 +1,46 @@
1+# Build a version of idris with a set of packages visible
2+# packages: The packages visible to idris
3+{ stdenv, idris }: packages: stdenv.mkDerivation {
4+ inherit (idris) name;
5+
6+ buildInputs = packages;
7+
8+ preHook = ''
9+ mkdir -p $out/lib/${idris.name}
10+
11+ installIdrisLib () {
12+ if [ -d $1/lib/${idris.name} ]; then
13+ ln -sv $1/lib/${idris.name}/* $out/lib/${idris.name}
14+ fi
15+ }
16+
17+ envHooks+=(installIdrisLib)
18+ '';
19+
20+ unpackPhase = ''
21+ cat >idris.c <<EOF
22+ #include <stdlib.h>
23+ #include <unistd.h>
24+ #include <stdio.h>
25+
26+ int main (int argc, char ** argv) {
27+ /* idris currently only supports a single library path, so respect it if the user set it */
28+ setenv("IDRIS_LIBRARY_PATH", "$out/lib/${idris.name}", 0);
29+ execv("${idris}/bin/idris", argv);
30+ perror("executing ${idris}/bin/idris");
31+ return 127;
32+ }
33+ EOF
34+ '';
35+
36+ buildPhase = ''
37+ gcc -O3 -o idris idris.c
38+ '';
39+
40+ installPhase = ''
41+ mkdir -p $out/bin
42+ mv idris $out/bin
43+ '';
44+
45+ stripAllList = [ "bin" ];
46+}
pkgs/development/idris-modules/wl-pprint.nixnew file+27
@@ -0,0 +1,27 @@
1+{ build-idris-package
2+, fetchgit
3+, prelude
4+, base
5+, lib
6+, idris
7+}: build-idris-package {
8+ name = "wl-pprint";
9+
10+ src = fetchgit {
11+ url = "git://github.com/shayan-najd/wl-pprint.git";
12+ rev = "120f654b0b9838b57e10b163d3562d959439fb07";
13+ sha256 = "b5d02a9191973dd8915279e84a9b4df430eb252f429327f45eb8a047d8bb954d";
14+ };
15+
16+ propagatedBuildInputs = [ prelude base ];
17+
18+ meta = {
19+ description = "Wadler-Leijen pretty-printing library";
20+
21+ homepage = https://github.com/shayan-najd/wl-pprint;
22+
23+ license = lib.licenses.bsd2;
24+
25+ inherit (idris.meta) platforms;
26+ };
27+}
pkgs/top-level/all-packages.nix+4
@@ -4121,6 +4121,10 @@ let
41214121
41224122 icedtea_web = icedtea8_web;
41234123
4124+ idrisPackages = callPackage ../development/idris-modules {
4125+ inherit (haskellPackages) idris;
4126+ };
4127+
41244128 ikarus = callPackage ../development/compilers/ikarus { };
41254129
41264130 intercal = callPackage ../development/compilers/intercal { };