@@ -0,0 +1,59 @@
1+{ cabalexpr, pkgs, compiler ? "Ghc", os ? "OSX", arch ? "X86_64" }:
2+assert (builtins.elem compiler ["Ghc" "Ghcjs" "Nhc" "Yhc" "Hugs" "Hbc" "Helium" "Jhc" "Lhc" "Uhc" "Eta"]);
3+assert (builtins.elem os ["Linux" "Windows" "OSX" "FreeBSD" "OpenBSD" "NetBSD" "DragonFly" "Solaris" "AIX" "HPUX" "IRIX" "HaLVM" "Hurd" "IOS" "Android" "Ghcjs"]);
4+assert (builtins.elem arch ["I386" "X86_64" "PPC" "PPC64" "Sparc" "Arm" "Aarch64" "Mips" "SH" "IA64" "S390" "Alpha" "Hppa" "Rs6000" "M68k" "Vax" "JavaScript"]);
8+ collectAttr = a: s: pkgs.lib.lists.fold (e: acc: (if e ? ${a} then e.${a} else []) ++ acc) [] (builtins.attrValues s);
10+ # resolver for cabal license to nix license
11+ resolve = { license = stdenv: license: (import ./cabal-licenses.nix stdenv).${license}; };
13+ # cabal os, arch and compilers.
14+ cabal = import ./cabal-os-arch-comp.nix;
16+ expr0 = flags: let e = cabalexpr {
18+ # null out self references. Tests, Benchmarks, ...
19+ # naturally depend on the package (as a library), but
20+ # we don't want those dependencies.
21+ hsPkgs = pkgs.haskellPackages // { ${e.package.identifier.name} = null; };
22+ # We also need to do some system pkgs -> haskell pkgs
25+ # package-conf mappings.
26+ # pkgconfig name -> nix package
27+ pkgconfPkgs = { libpcre = pkgs.pcre; };
29+ compiler = cabal.compiler // { "is${compiler}" = true; };
30+ system = cabal.os // { "is${os}" = true; }
31+ // cabal.arch // { "is${arch}" = true; };
34+{ mkDerivation, stdenv, flags ? {} }:
35+let expr = expr0 (stdenv.lib.traceVal flags);
36+ pname = expr.package.identifier.name;
39+ version = expr.package.identifier.version;
42+ isLibrary = builtins.hasAttr pname expr.components;
43+ isExecutable = builtins.hasAttr "exes" expr.components;
45+ homepage = expr.package.homepage;
46+ description = expr.package.synopsis;
47+ license = resolve.license stdenv expr.package.license;
49+ configureFlags = pkgs.lib.mapAttrsToList (flag: enabled: (if enabled then "-f" else "-f-") + flag) flags;
50+} // pkgs.lib.optionalAttrs (builtins.hasAttr pname expr.components) {
51+ libraryHaskellDepends = expr.components.${pname}.depends;
52+ libraryPkgconfigDepends = expr.components.${pname}.pkgconfig or [];
53+} // pkgs.lib.optionalAttrs (builtins.hasAttr "exes" expr.components) {
54+ executableHaskellDepends = collectAttr "depends" expr.components.exes;
55+} // pkgs.lib.optionalAttrs (builtins.hasAttr "tests" expr.components) {
56+ testHaskellDepends = collectAttr "depends" expr.components.tests;
57+} // pkgs.lib.optionalAttrs (builtins.hasAttr "benchmarks" expr.components) {
58+ benchmarkHaskellDepends = collectAttr "depends" expr.components.benchmarks;