mirror of
https://github.com/ilyakooo0/haskell.nix.git
synced 2024-09-11 06:55:40 +03:00
initial checkin
This commit is contained in:
commit
3c3267a086
5
compat/cabal-licenses.nix
Normal file
5
compat/cabal-licenses.nix
Normal file
@ -0,0 +1,5 @@
|
||||
stdenv: with stdenv.lib.licenses;
|
||||
{ BSD-3-Clause = bsd3;
|
||||
BSD-2-Clause = bsd2;
|
||||
MIT = mit;
|
||||
}
|
57
compat/cabal-os-arch-comp.nix
Normal file
57
compat/cabal-os-arch-comp.nix
Normal file
@ -0,0 +1,57 @@
|
||||
# Predicates used in conditional
|
||||
# cabal expressions.
|
||||
{
|
||||
compiler = {
|
||||
# Haskell compilers
|
||||
isGhc = false;
|
||||
isGhcjs = false;
|
||||
isNhc = false;
|
||||
isYhc = false;
|
||||
isHugs = false;
|
||||
isHbc = false;
|
||||
isHelium = false;
|
||||
isJhc = false;
|
||||
isLhc = false;
|
||||
isUhc = false;
|
||||
isEta = false;
|
||||
};
|
||||
os = {
|
||||
# OSs
|
||||
isLinux = false;
|
||||
isWindows = false;
|
||||
isOSX = false;
|
||||
isFreeBSD = false;
|
||||
isOpenBSD = false;
|
||||
isNetBSD = false;
|
||||
isDragonFly = false;
|
||||
isSolaris = false;
|
||||
isAIX = false;
|
||||
isHPUX = false;
|
||||
isIRIX = false;
|
||||
isHalvm = false;
|
||||
isHurd = false;
|
||||
isIOS = false;
|
||||
isAndroid = false;
|
||||
isGhcjs = false;
|
||||
};
|
||||
arch = {
|
||||
# Archs
|
||||
isI386 = false;
|
||||
isX86_64 = false;
|
||||
isPPC = false;
|
||||
isPPC64 = false;
|
||||
isSparc = false;
|
||||
isArm = false;
|
||||
isAArch64= false;
|
||||
isMips = false;
|
||||
isSH = false;
|
||||
isIA64 = false;
|
||||
isS390 = false;
|
||||
isAlpha = false;
|
||||
isHppa = false;
|
||||
isRs6000 = false;
|
||||
isM68k = false;
|
||||
isVax = false;
|
||||
isJavaScript = false;
|
||||
};
|
||||
}
|
59
compat/driver.nix
Normal file
59
compat/driver.nix
Normal file
@ -0,0 +1,59 @@
|
||||
{ cabalexpr, pkgs, compiler ? "Ghc", os ? "OSX", arch ? "X86_64" }:
|
||||
assert (builtins.elem compiler ["Ghc" "Ghcjs" "Nhc" "Yhc" "Hugs" "Hbc" "Helium" "Jhc" "Lhc" "Uhc" "Eta"]);
|
||||
assert (builtins.elem os ["Linux" "Windows" "OSX" "FreeBSD" "OpenBSD" "NetBSD" "DragonFly" "Solaris" "AIX" "HPUX" "IRIX" "HaLVM" "Hurd" "IOS" "Android" "Ghcjs"]);
|
||||
assert (builtins.elem arch ["I386" "X86_64" "PPC" "PPC64" "Sparc" "Arm" "Aarch64" "Mips" "SH" "IA64" "S390" "Alpha" "Hppa" "Rs6000" "M68k" "Vax" "JavaScript"]);
|
||||
|
||||
with rec {
|
||||
# utilities
|
||||
collectAttr = a: s: pkgs.lib.lists.fold (e: acc: (if e ? ${a} then e.${a} else []) ++ acc) [] (builtins.attrValues s);
|
||||
|
||||
# resolver for cabal license to nix license
|
||||
resolve = { license = stdenv: license: (import ./cabal-licenses.nix stdenv).${license}; };
|
||||
|
||||
# cabal os, arch and compilers.
|
||||
cabal = import ./cabal-os-arch-comp.nix;
|
||||
|
||||
expr0 = flags: let e = cabalexpr {
|
||||
inherit flags;
|
||||
# null out self references. Tests, Benchmarks, ...
|
||||
# naturally depend on the package (as a library), but
|
||||
# we don't want those dependencies.
|
||||
hsPkgs = pkgs.haskellPackages // { ${e.package.identifier.name} = null; };
|
||||
# We also need to do some system pkgs -> haskell pkgs
|
||||
# resolution.
|
||||
pkgs = pkgs // { };
|
||||
# package-conf mappings.
|
||||
# pkgconfig name -> nix package
|
||||
pkgconfPkgs = { libpcre = pkgs.pcre; };
|
||||
|
||||
compiler = cabal.compiler // { "is${compiler}" = true; };
|
||||
system = cabal.os // { "is${os}" = true; }
|
||||
// cabal.arch // { "is${arch}" = true; };
|
||||
}; in e;
|
||||
};
|
||||
{ mkDerivation, stdenv, flags ? {} }:
|
||||
let expr = expr0 (stdenv.lib.traceVal flags);
|
||||
pname = expr.package.identifier.name;
|
||||
in mkDerivation ({
|
||||
inherit pname;
|
||||
version = expr.package.identifier.version;
|
||||
sha256 = null;
|
||||
|
||||
isLibrary = builtins.hasAttr pname expr.components;
|
||||
isExecutable = builtins.hasAttr "exes" expr.components;
|
||||
|
||||
homepage = expr.package.homepage;
|
||||
description = expr.package.synopsis;
|
||||
license = resolve.license stdenv expr.package.license;
|
||||
|
||||
configureFlags = pkgs.lib.mapAttrsToList (flag: enabled: (if enabled then "-f" else "-f-") + flag) flags;
|
||||
} // pkgs.lib.optionalAttrs (builtins.hasAttr pname expr.components) {
|
||||
libraryHaskellDepends = expr.components.${pname}.depends;
|
||||
libraryPkgconfigDepends = expr.components.${pname}.pkgconfig or [];
|
||||
} // pkgs.lib.optionalAttrs (builtins.hasAttr "exes" expr.components) {
|
||||
executableHaskellDepends = collectAttr "depends" expr.components.exes;
|
||||
} // pkgs.lib.optionalAttrs (builtins.hasAttr "tests" expr.components) {
|
||||
testHaskellDepends = collectAttr "depends" expr.components.tests;
|
||||
} // pkgs.lib.optionalAttrs (builtins.hasAttr "benchmarks" expr.components) {
|
||||
benchmarkHaskellDepends = collectAttr "depends" expr.components.benchmarks;
|
||||
})
|
20
compat/host-map.nix
Normal file
20
compat/host-map.nix
Normal file
@ -0,0 +1,20 @@
|
||||
stdenv: with stdenv.hostPlatform; {
|
||||
os = if isLinux then "Linux" else
|
||||
if isWindows then "Windows" else
|
||||
if isMacOS then "OSX" else
|
||||
if isFreeBSD then "FreeBSD" else
|
||||
if isOpenBSD then "OpenBSD" else
|
||||
if isNetBSD then "NetBSD" else
|
||||
if isHurd then "Hurd" else
|
||||
if isiOS then "IOS" else
|
||||
if isAndroid then "Android" else
|
||||
throw "Unknown OS";
|
||||
arch = if isx86 && is32bit then "I386" else
|
||||
if isx86 && is64bit then "X86_64" else
|
||||
if isPowerPC && is32bit then "PPC" else
|
||||
if isPowerPC && is64bit then "PPC64" else
|
||||
if isArm && is32bit then "Arm" else
|
||||
if isArm && is64bit then "Aarch64" else
|
||||
if isMips then "Mips" else
|
||||
throw "Unknown Arch";
|
||||
}
|
Loading…
Reference in New Issue
Block a user