diff --git a/pkgs/build-support/cabal/ghcjs.nix b/pkgs/build-support/cabal/ghcjs.nix new file mode 100644 index 00000000000..346165571d7 --- /dev/null +++ b/pkgs/build-support/cabal/ghcjs.nix @@ -0,0 +1,279 @@ +# generic builder for Cabal packages + +{ stdenv, fetchurl, lib, pkgconfig, ghcjs, ghc, Cabal, jailbreakCabal, glibcLocales +, gnugrep, coreutils, hscolour # hscolour is unused +, enableLibraryProfiling ? false +, enableSharedLibraries ? false +, enableSharedExecutables ? false +, enableStaticLibraries ? true +, enableCheckPhase ? stdenv.lib.versionOlder "7.4" ghc.version +, enableHyperlinkSource ? false +, extension ? (self : super : {}) +}: + +let + enableFeature = stdenv.lib.enableFeature; + versionOlder = stdenv.lib.versionOlder; + optional = stdenv.lib.optional; + optionals = stdenv.lib.optionals; + optionalString = stdenv.lib.optionalString; + filter = stdenv.lib.filter; +in + +builtins.trace (ghc.parent.CabalGhcjs.version or null) { + mkDerivation = + args : # arguments for the individual package, can modify the defaults + let # These attributes are removed in the end. This is in order not to spoil the build + # environment overly, but also to keep hash-backwards-compatible with the old cabal.nix. + internalAttrs = [ + "internalAttrs" "buildDepends" "buildTools" "extraLibraries" "pkgconfigDepends" + "isLibrary" "isExecutable" "testDepends" + ]; + + # Stuff happening after the user preferences have been processed. We remove + # internal attributes and strip null elements from the dependency lists, all + # in the interest of keeping hashes stable. + postprocess = + x : (removeAttrs x internalAttrs) // { + buildInputs = filter (y : ! (y == null)) x.buildInputs; + propagatedBuildInputs = filter (y : ! (y == null)) x.propagatedBuildInputs; + propagatedUserEnvPkgs = filter (y : ! (y == null)) x.propagatedUserEnvPkgs; + doCheck = enableCheckPhase && x.doCheck; + hyperlinkSource = enableHyperlinkSource && x.hyperlinkSource; + }; + + defaults = + self : { # self is the final version of the attribute set + + # pname should be defined by the client to be the package basename + # version should be defined by the client to be the package version + + # fname is the internal full name of the package + fname = "${self.pname}-${self.version}"; + + # name is the external full name of the package; usually we prefix + # all packages with haskell- to avoid name clashes for libraries; + # if that is not desired (for applications), name can be set to + # fname. + name = if self.isLibrary then + if enableLibraryProfiling && self.enableSharedLibraries then + "haskell-${self.pname}-ghcjs${ghc.ghc.version}-${self.version}-profiling-shared" + else if enableLibraryProfiling && !self.enableSharedLibraries then + "haskell-${self.pname}-ghcjs${ghc.ghc.version}-${self.version}-profiling" + else if !enableLibraryProfiling && self.enableSharedLibraries then + "haskell-${self.pname}-ghcjs${ghc.ghc.version}-${self.version}-shared" + else + "haskell-${self.pname}-ghcjs${ghc.ghc.version}-${self.version}" + else + "${self.pname}-${self.version}"; + + # the default download location for Cabal packages is Hackage, + # you still have to specify the checksum + src = fetchurl { + url = "mirror://hackage/${self.pname}/${self.fname}.tar.gz"; + inherit (self) sha256; + }; + + # default buildInputs are just ghc, if more buildInputs are required + # buildInputs can be extended by the client by using extraBuildInputs, + # but often propagatedBuildInputs is preferable anyway + buildInputs = [ghc ghc.ghc.parent.CabalGhcjs] ++ self.extraBuildInputs; + extraBuildInputs = self.buildTools ++ + (optionals self.doCheck self.testDepends) ++ + (if self.pkgconfigDepends == [] then [] else [pkgconfig]) ++ + (if self.isLibrary then [] else self.buildDepends ++ self.extraLibraries ++ self.pkgconfigDepends); + + # we make sure that propagatedBuildInputs is defined, so that we don't + # have to check for its existence + propagatedBuildInputs = if self.isLibrary then self.buildDepends ++ self.extraLibraries ++ self.pkgconfigDepends else []; + + # By default, also propagate all dependencies to the user environment. This is required, otherwise packages would be broken, because + # GHC also needs all dependencies to be available. + propagatedUserEnvPkgs = if self.isLibrary then self.buildDepends else []; + + # library directories that have to be added to the Cabal files + extraLibDirs = []; + + # build-depends Cabal field + buildDepends = []; + + # target(s) passed to the cabal build phase as an argument + buildTarget = ""; + + # build-depends Cabal fields stated in test-suite stanzas + testDepends = []; + + # target(s) passed to the cabal test phase as an argument + testTarget = ""; + + # build-tools Cabal field + buildTools = []; + + # extra-libraries Cabal field + extraLibraries = []; + + # pkgconfig-depends Cabal field + pkgconfigDepends = []; + + isLibrary = ! self.isExecutable; + isExecutable = false; + + # ignore version restrictions on the build inputs that the cabal file might specify + jailbreak = false; + + # pass the '--enable-split-objs' flag to cabal in the configure stage + enableSplitObjs = false; # !stdenv.isDarwin; # http://hackage.haskell.org/trac/ghc/ticket/4013 + + # pass the '--enable-tests' flag to cabal in the configure stage + # and run any regression test suites the package might have + doCheck = false; #enableCheckPhase; + + # pass the '--hyperlink-source' flag to ./Setup haddock + hyperlinkSource = enableHyperlinkSource; + + # abort the build if the configure phase detects that the package + # depends on multiple versions of the same build input + strictConfigurePhase = true; + + # pass the '--enable-library-vanilla' flag to cabal in the + # configure stage to enable building shared libraries + inherit enableStaticLibraries; + + # pass the '--enable-shared' flag to cabal in the configure + # stage to enable building shared libraries + inherit enableSharedLibraries; + + # pass the '--enable-executable-dynamic' flag to cabal in + # the configure stage to enable linking shared libraries + inherit enableSharedExecutables; + + extraConfigureFlags = [ + (enableFeature self.enableSplitObjs "split-objs") + (enableFeature enableLibraryProfiling "library-profiling") + (enableFeature true "shared") + (optional (versionOlder "7" ghc.version) (enableFeature self.enableStaticLibraries "library-vanilla")) + (optional (versionOlder "7.4" ghc.version) (enableFeature self.enableSharedExecutables "executable-dynamic")) + (optional (versionOlder "7" ghc.version) (enableFeature self.doCheck "tests")) + ]; + + # GHC needs the locale configured during the Haddock phase. + LANG = "en_US.UTF-8"; + LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive"; + + # compiles Setup and configures + configurePhase = '' + set -x + eval "$preConfigure" + + ${optionalString self.jailbreak "${ghc.ghc.parent.jailbreakCabal}/bin/jailbreak-cabal ${self.pname}.cabal"} + + PATH=$PATH:${ghc.ghc.ghc}/bin + + for i in Setup.hs Setup.lhs; do + test -f $i && ghc --make $i + done + + for p in $extraBuildInputs $propagatedBuildInputs $propagatedNativeBuildInputs; do + PkgDir="$p/lib/ghcjs-${ghc.ghc.version}_ghc-${ghc.ghc.ghc.version}/package.conf.d" + if [ -f "$PkgDir/package.cache" ]; then + extraConfigureFlags+=" --package-db=$PkgDir" + continue; + fi + if [ -d "$p/include" ]; then + extraConfigureFlags+=" --extra-include-dirs=$p/include" + fi + for d in lib{,64}; do + if [ -d "$p/$d" ]; then + extraConfigureFlags+=" --extra-lib-dirs=$p/$d" + fi + done + done + + configureFlags+=" --package-db=/nix/store/a68nrd3slc39pgl4s3n485s6nfk3mnbi-haskell-ghcjs-ghc7.8.2-0.1.0-shared/share/ghcjs/x86_64-linux-0.1.0-7.8.2/package.conf.d" + + ${optionalString (self.enableSharedExecutables && self.stdenv.isLinux) '' + configureFlags+=" --ghc-option=-optl=-Wl,-rpath=$out/lib/${ghc.ghc.name}/${self.pname}-${self.version}"; + ''} + ${optionalString (self.enableSharedExecutables && self.stdenv.isDarwin) '' + configureFlags+=" --ghc-option=-optl=-Wl,-headerpad_max_install_names"; + ''} + + echo "configure flags: $extraConfigureFlags $configureFlags" + ./Setup configure --ghcjs --verbose --prefix="$out" --libdir='$prefix/lib/$compiler' \ + --libsubdir='$pkgid' $extraConfigureFlags $configureFlags 2>&1 \ + ${optionalString self.strictConfigurePhase '' + | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log" + if ${gnugrep}/bin/egrep -q '^Warning:.*depends on multiple versions' "$NIX_BUILD_TOP/cabal-configure.log"; then + echo >&2 "*** abort because of serious configure-time warning from Cabal" + exit 1 + fi + ''} + + eval "$postConfigure" + ''; + + # builds via Cabal + buildPhase = '' + eval "$preBuild" + + ./Setup build ${self.buildTarget} + + export GHC_PACKAGE_PATH=$(${ghc.GHCPackages}) + #test -n "$noHaddock" || ./Setup haddock --html --hoogle \ + # ${optionalString self.hyperlinkSource "--hyperlink-source"} + + eval "$postBuild" + ''; + + checkPhase = optional self.doCheck '' + eval "$preCheck" + + ./Setup test ${self.testTarget} + + eval "$postCheck" + ''; + + # installs via Cabal; creates a registration file for nix-support + # so that the package can be used in other Haskell-builds; also + # adds all propagated build inputs to the user environment packages + installPhase = '' + eval "$preInstall" + + ./Setup copy + + ensureDir $out/bin # necessary to get it added to PATH + + local confDir=$out/lib/ghcjs-${ghc.ghc.version}_ghc-${ghc.ghc.ghc.version}/package.conf.d + local installedPkgConf=$confDir/${self.fname}.installedconf + local pkgConf=$confDir/${self.fname}.conf + ensureDir $confDir + ./Setup register --gen-pkg-config=$pkgConf + if test -f $pkgConf; then + echo '[]' > $installedPkgConf + GHC_PACKAGE_PATH=$installedPkgConf ghcjs-pkg --global register $pkgConf --force --package-db=$confDir || true + ghcjs-pkg recache --package-db=$confDir + fi + + if test -f $out/nix-support/propagated-native-build-inputs; then + ln -s $out/nix-support/propagated-native-build-inputs $out/nix-support/propagated-user-env-packages + fi + + ${optionalString (self.enableSharedExecutables && self.isExecutable && self.stdenv.isDarwin) '' + for exe in $out/bin/* ; do + install_name_tool -add_rpath \ + $out/lib/${ghc.ghc.name}/${self.pname}-${self.version} $exe + done + ''} + + eval "$postInstall" + ''; + + # We inherit stdenv and ghc so that they can be used + # in Cabal derivations. + inherit stdenv ghc; + }; + in + stdenv.mkDerivation (postprocess (let super = defaults self // args self; + self = super // extension self super; + in self)); +} diff --git a/pkgs/development/compilers/ghcjs/wrapper.nix b/pkgs/development/compilers/ghcjs/wrapper.nix new file mode 100644 index 00000000000..fa1336fec27 --- /dev/null +++ b/pkgs/development/compilers/ghcjs/wrapper.nix @@ -0,0 +1,77 @@ +{ stdenv, ghc, makeWrapper, coreutils, writeScript }: +let + ghcjs = ghc; + packageDBFlag = "-package-db"; + + GHCGetPackages = writeScript "ghc-get-packages.sh" '' + #! ${stdenv.shell} + # Usage: + # $1: version of GHC + # $2: invocation path of GHC + # $3: prefix + version="$1" + if test -z "$3"; then + prefix="${packageDBFlag} " + else + prefix="$3" + fi + PATH="$PATH:$2" + IFS=":" + for p in $PATH; do + for i in "$p/../share/ghcjs/$system-${ghcjs.version}-${ghcjs.ghc.version}"{,/lib}"/package.conf.d" "$p/../lib/ghcjs-${ghc.version}_ghc-${ghc.ghc.version}/package.conf.d" ; do + # output takes place here + test -f $i/package.cache && echo -n " $prefix$i" + done + done + ''; + + GHCPackages = writeScript "ghc-packages.sh" '' + #! ${stdenv.shell} -e + declare -A GHC_PACKAGES_HASH # using bash4 hashs to get uniq paths + + for arg in $(${GHCGetPackages} ${ghcjs.version} "$(dirname $0)"); do # Why is ghc.version passed in from here instead of captured in the other script directly? + case "$arg" in + ${packageDBFlag}) ;; + *) + CANONICALIZED="$(${coreutils}/bin/readlink -f -- "$arg")" + GHC_PACKAGES_HASH["$CANONICALIZED"]= ;; + esac + done + + for path in ''${!GHC_PACKAGES_HASH[@]}; do + echo -n "$path:" + done + ''; +in +stdenv.mkDerivation { + name = "ghcjs-ghc${ghcjs.ghc.version}-${ghcjs.version}-wrapper"; + + buildInputs = [makeWrapper]; + propagatedBuildInputs = [ghcjs]; + + unpackPhase = "true"; + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + for prg in ghcjs ; do + makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$(${GHCGetPackages} ${ghcjs.version} \"\$(dirname \$0)\")" + done + for prg in ghcjs-pkg ; do + makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$(${GHCGetPackages} ${ghcjs.version} \"\$(dirname \$0)\" -${packageDBFlag}=)" + done + + mkdir -p $out/nix-support + ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages + + mkdir -p $out/share/doc + ln -s $ghc/lib $out/lib + ln -s $ghc/share/doc/ghc $out/share/doc/ghc-${ghcjs.version} + + runHook postInstall + ''; + + ghc = ghcjs; + inherit GHCGetPackages GHCPackages; + inherit (ghcjs) meta version; +} diff --git a/pkgs/development/libraries/haskell/derive/default.nix b/pkgs/development/libraries/haskell/derive/default.nix index 5dba1b6af56..1f8584a0277 100644 --- a/pkgs/development/libraries/haskell/derive/default.nix +++ b/pkgs/development/libraries/haskell/derive/default.nix @@ -1,4 +1,4 @@ -{ cabal, filepath, haskellSrcExts, syb, transformers, uniplate }: +{ cabal, process, filepath, haskellSrcExts, syb, transformers, uniplate }: cabal.mkDerivation (self: { pname = "derive"; @@ -7,7 +7,7 @@ cabal.mkDerivation (self: { isLibrary = true; isExecutable = true; buildDepends = [ - filepath haskellSrcExts syb transformers uniplate + process filepath haskellSrcExts syb transformers uniplate ]; meta = { homepage = "http://community.haskell.org/~ndm/derive/"; diff --git a/pkgs/development/libraries/haskell/old-time/1.1.0.2.nix b/pkgs/development/libraries/haskell/old-time/1.1.0.2.nix new file mode 100644 index 00000000000..eab8e3e5c63 --- /dev/null +++ b/pkgs/development/libraries/haskell/old-time/1.1.0.2.nix @@ -0,0 +1,12 @@ +{ cabal }: + +cabal.mkDerivation (self: { + pname = "old-time"; + version = "1.1.0.2"; + sha256 = "1nrqbpwxsmga13gcyn7bg25gkm61fmix07gm76d1f1i4impgqw1r"; + meta = { + description = "Time library"; + license = self.stdenv.lib.licenses.bsd3; + platforms = self.ghc.meta.platforms; + }; +}) diff --git a/pkgs/development/tools/haskell/Cabal-ghcjs/default.nix b/pkgs/development/tools/haskell/Cabal-ghcjs/default.nix index db0447030f0..6613adba19c 100644 --- a/pkgs/development/tools/haskell/Cabal-ghcjs/default.nix +++ b/pkgs/development/tools/haskell/Cabal-ghcjs/default.nix @@ -4,7 +4,7 @@ }: cabal.mkDerivation (self: { - pname = "Cabal-ghcjs"; + pname = "Cabal"; version = "9e87d6a3"; src = fetchgit { url = git://github.com/ghcjs/cabal.git; diff --git a/pkgs/development/tools/misc/cpphs/default.nix b/pkgs/development/tools/misc/cpphs/default.nix index 72a6571f3cc..ce6042de7fa 100644 --- a/pkgs/development/tools/misc/cpphs/default.nix +++ b/pkgs/development/tools/misc/cpphs/default.nix @@ -1,4 +1,4 @@ -{ cabal, polyparse }: +{ cabal, polyparse, oldTime }: cabal.mkDerivation (self: { pname = "cpphs"; @@ -6,7 +6,7 @@ cabal.mkDerivation (self: { sha256 = "0rmcq66wn7lsc5g1wk6bbsr7jiw8h6bz5cbvdywnv7vmwsx8gh51"; isLibrary = true; isExecutable = true; - buildDepends = [ polyparse ]; + buildDepends = [ oldTime polyparse ]; meta = { homepage = "http://projects.haskell.org/cpphs/"; description = "A liberalised re-implementation of cpp, the C pre-processor"; diff --git a/pkgs/top-level/haskell-defaults.nix b/pkgs/top-level/haskell-defaults.nix index bd447aed065..6d58eee927e 100644 --- a/pkgs/top-level/haskell-defaults.nix +++ b/pkgs/top-level/haskell-defaults.nix @@ -135,20 +135,23 @@ # Abstraction for Haskell packages collections packagesFun = makeOverridable - ({ ghcPath + ({ ghcPath ? null + , ghc ? callPackage ghcPath ({ ghc = ghcBinary; } // extraArgs) , ghcBinary ? ghc6101Binary , prefFun , extension ? (self : super : {}) , profExplicit ? false, profDefault ? false , modifyPrio ? lowPrio , extraArgs ? {} + , cabalPackage ? import ../build-support/cabal + , ghcWrapperPackage ? import ../development/compilers/ghc/wrapper.nix } : let haskellPackagesClass = import ./haskell-packages.nix { - inherit pkgs newScope modifyPrio; + inherit pkgs newScope modifyPrio cabalPackage ghcWrapperPackage; enableLibraryProfiling = if profExplicit then profDefault else config.cabal.libraryProfiling or profDefault; - ghc = callPackage ghcPath ({ ghc = ghcBinary; } // extraArgs); + inherit ghc; }; haskellPackagesPrefsClass = self : let super = haskellPackagesClass self; in super // prefFun self super; haskellPackagesExtensionClass = self : let super = haskellPackagesPrefsClass self; in super // extension self super; @@ -214,9 +217,85 @@ }; }; - packages_ghcjs = packages_ghc782 // { - ghc = ../development/tools/haskell/ghcjs; - }; + packages_ghcjs = + let parent = packages_ghc782.override { + extension = self: super: { + Cabal = packages_ghc782.CabalGhcjs; + }; + }; + in packages { + ghc = parent.ghcjs // { inherit parent; }; + cabalPackage = import ../build-support/cabal/ghcjs.nix; + ghcWrapperPackage = import ../development/compilers/ghcjs/wrapper.nix; + prefFun = self : super : super // { + # This is the list of packages that are built into a booted ghcjs installation +# Cabal_1_19_2 = null; +# Cabal = self.Cabal_1_19_2; + Cabal = packages_ghc782.CabalGhcjs; + aeson_0_7_0_4 = null; + aeson = self.aeson_0_7_0_4; + array_0_5_0_0 = null; + array = self.array_0_5_0_0; + attoparsec_0_11_3_1 = null; + attoparsec = self.attoparsec_0_11_3_1; + base_4_7_0_0 = null; + base = self.base_4_7_0_0; + bytestring_0_10_4_0 = null; + bytestring = self.bytestring_0_10_4_0; + containers_0_5_5_1 = null; + containers = self.containers_0_5_5_1; + deepseq_1_3_0_2 = null; + deepseq = self.deepseq_1_3_0_2; + directory_1_2_1_0 = null; + directory = self.directory_1_2_1_0; + dlist_0_7_1 = null; + dlist = self.dlist_0_7_1; + filepath_1_3_0_2 = null; + filepath = self.filepath_1_3_0_2; + ghcPrim_0_3_1_0 = null; + ghcPrim = self.ghcPrim_0_3_1_0; + ghcjsBase_0_1_0_0 = null; + ghcjsBase = self.ghcjsBase_0_1_0_0; + ghcjsPrim_0_1_0_0 = null; + ghcjsPrim = self.ghcjsPrim_0_1_0_0; + hashable_1_2_1_0 = null; + hashable = self.hashable_1_2_1_0; + integerGmp_0_5_1_0 = null; + integerGmp = self.integerGmp_0_5_1_0; + mtl_2_1_3_1 = null; + mtl = self.mtl_2_1_3_1; + oldLocale_1_0_0_6 = null; + oldLocale = self.oldLocale_1_0_0_6; + pretty_1_1_1_1 = null; + pretty = self.pretty_1_1_1_1; + primitive_0_5_3_0 = null; + primitive = self.primitive_0_5_3_0; + # process_1_2_0_0 = null; + # process = self.process_1_2_0_0; + scientific_0_2_0_2 = null; + scientific = self.scientific_0_2_0_2; + syb_0_4_2 = null; + syb = self.syb_0_4_2; + templateHaskell_2_9_0_0 = null; + templateHaskell = self.templateHaskell_2_9_0_0; + text_1_1_1_3 = null; + text = self.text_1_1_1_3; + time_1_4_2 = null; + time = self.time_1_4_2; + transformers_0_3_0_0 = null; + transformers = self.transformers_0_3_0_0; + unix_2_7_0_1 = null; + unix = self.unix_2_7_0_1; + unorderedContainers_0_2_5_0 = null; + unorderedContainers = self.unorderedContainers_0_2_5_0; + vector_0_10_11_0 = null; + vector = self.vector_0_10_11_0; + # These are necessary for compatibility with ghcjs's default libs + transformersCompat = self.transformersCompat_0_3_3; + oldTime = self.oldTime_1_1_0_2; + process = self.process_1_2_0_0; # ghcjs-boot seems to install process incorrectly, for some reason, so reinstall it + }; + }; packages_ghc782 = packages { ghcPath = ../development/compilers/ghc/7.8.2.nix; diff --git a/pkgs/top-level/haskell-packages.nix b/pkgs/top-level/haskell-packages.nix index 53816711893..f0f561c9c96 100644 --- a/pkgs/top-level/haskell-packages.nix +++ b/pkgs/top-level/haskell-packages.nix @@ -43,7 +43,7 @@ # # For most packages, however, we keep only one version, and use default.nix. -{ pkgs, newScope, ghc, modifyPrio ? (x : x) +{ pkgs, newScope, ghc, cabalPackage, ghcWrapperPackage, modifyPrio ? (x : x) , enableLibraryProfiling ? false , enableSharedLibraries ? pkgs.stdenv.lib.versionOlder "7.7" ghc.version , enableSharedExecutables ? pkgs.stdenv.lib.versionOlder "7.7" ghc.version @@ -74,7 +74,7 @@ self : let callPackage = x : y : modifyPrio (newScope self x y); in # refers to the function argument at the # top of this file. - ghc = callPackage ../development/compilers/ghc/wrapper.nix { + ghc = callPackage ghcWrapperPackage { ghc = ghc; # refers to ghcPlain }; @@ -94,7 +94,7 @@ self : let callPackage = x : y : modifyPrio (newScope self x y); in # This is the Cabal builder, the function we use to build most Haskell # packages. It isn't the Cabal library, which is spelled "Cabal". - cabal = callPackage ../build-support/cabal { + cabal = callPackage cabalPackage { Cabal = null; # prefer the Cabal version shipped with the compiler hscolour = self.hscolourBootstrap; inherit enableLibraryProfiling enableCheckPhase @@ -2673,6 +2673,8 @@ self : let callPackage = x : y : modifyPrio (newScope self x y); in cake3 = callPackage ../development/tools/haskell/cake3 {}; + oldTime_1_1_0_2 = callPackage ../development/libraries/haskell/old-time/1.1.0.2.nix {}; + oldTime = null; # By default, use the built-in old-time library cpphs = callPackage ../development/tools/misc/cpphs {}; DrIFT = callPackage ../development/tools/haskell/DrIFT {};