on iko/ghcjs-patch-master help sign in
initial checkin
commit3c3267a0865d59dfcec928871d3df2c4e0fe9ae4 authorMoritz Angermann <moritz.angermann@gmail.com> dateFri 20 Apr 2018, 18:00 (9 years ago)
4 files changed+141
compat/cabal-licenses.nix+5 compat/cabal-os-arch-comp.nix+57 compat/driver.nix+59 compat/host-map.nix+20
compat/cabal-licenses.nixnew file+5
@@ -0,0 +1,5 @@
1+stdenv: with stdenv.lib.licenses;
2+{ BSD-3-Clause = bsd3;
3+ BSD-2-Clause = bsd2;
4+ MIT = mit;
5+}
compat/cabal-os-arch-comp.nixnew file+57
@@ -0,0 +1,57 @@
1+# Predicates used in conditional
2+# cabal expressions.
3+{
4+ compiler = {
5+ # Haskell compilers
6+ isGhc = false;
7+ isGhcjs = false;
8+ isNhc = false;
9+ isYhc = false;
10+ isHugs = false;
11+ isHbc = false;
12+ isHelium = false;
13+ isJhc = false;
14+ isLhc = false;
15+ isUhc = false;
16+ isEta = false;
17+ };
18+ os = {
19+ # OSs
20+ isLinux = false;
21+ isWindows = false;
22+ isOSX = false;
23+ isFreeBSD = false;
24+ isOpenBSD = false;
25+ isNetBSD = false;
26+ isDragonFly = false;
27+ isSolaris = false;
28+ isAIX = false;
29+ isHPUX = false;
30+ isIRIX = false;
31+ isHalvm = false;
32+ isHurd = false;
33+ isIOS = false;
34+ isAndroid = false;
35+ isGhcjs = false;
36+ };
37+ arch = {
38+ # Archs
39+ isI386 = false;
40+ isX86_64 = false;
41+ isPPC = false;
42+ isPPC64 = false;
43+ isSparc = false;
44+ isArm = false;
45+ isAArch64= false;
46+ isMips = false;
47+ isSH = false;
48+ isIA64 = false;
49+ isS390 = false;
50+ isAlpha = false;
51+ isHppa = false;
52+ isRs6000 = false;
53+ isM68k = false;
54+ isVax = false;
55+ isJavaScript = false;
56+ };
57+}
compat/driver.nixnew file+59
@@ -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"]);
5+
6+with rec {
7+ # utilities
8+ collectAttr = a: s: pkgs.lib.lists.fold (e: acc: (if e ? ${a} then e.${a} else []) ++ acc) [] (builtins.attrValues s);
9+
10+ # resolver for cabal license to nix license
11+ resolve = { license = stdenv: license: (import ./cabal-licenses.nix stdenv).${license}; };
12+
13+ # cabal os, arch and compilers.
14+ cabal = import ./cabal-os-arch-comp.nix;
15+
16+ expr0 = flags: let e = cabalexpr {
17+ inherit flags;
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
23+ # resolution.
24+ pkgs = pkgs // { };
25+ # package-conf mappings.
26+ # pkgconfig name -> nix package
27+ pkgconfPkgs = { libpcre = pkgs.pcre; };
28+
29+ compiler = cabal.compiler // { "is${compiler}" = true; };
30+ system = cabal.os // { "is${os}" = true; }
31+ // cabal.arch // { "is${arch}" = true; };
32+ }; in e;
33+};
34+{ mkDerivation, stdenv, flags ? {} }:
35+let expr = expr0 (stdenv.lib.traceVal flags);
36+ pname = expr.package.identifier.name;
37+in mkDerivation ({
38+ inherit pname;
39+ version = expr.package.identifier.version;
40+ sha256 = null;
41+
42+ isLibrary = builtins.hasAttr pname expr.components;
43+ isExecutable = builtins.hasAttr "exes" expr.components;
44+
45+ homepage = expr.package.homepage;
46+ description = expr.package.synopsis;
47+ license = resolve.license stdenv expr.package.license;
48+
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;
59+})
compat/host-map.nixnew file+20
@@ -0,0 +1,20 @@
1+stdenv: with stdenv.hostPlatform; {
2+ os = if isLinux then "Linux" else
3+ if isWindows then "Windows" else
4+ if isMacOS then "OSX" else
5+ if isFreeBSD then "FreeBSD" else
6+ if isOpenBSD then "OpenBSD" else
7+ if isNetBSD then "NetBSD" else
8+ if isHurd then "Hurd" else
9+ if isiOS then "IOS" else
10+ if isAndroid then "Android" else
11+ throw "Unknown OS";
12+ arch = if isx86 && is32bit then "I386" else
13+ if isx86 && is64bit then "X86_64" else
14+ if isPowerPC && is32bit then "PPC" else
15+ if isPowerPC && is64bit then "PPC64" else
16+ if isArm && is32bit then "Arm" else
17+ if isArm && is64bit then "Aarch64" else
18+ if isMips then "Mips" else
19+ throw "Unknown Arch";
20+}