@@ -56,10 +56,6 @@ let isCross = (ghc.cross or null) != null; in
5656, hardeningDisable ? lib . optional ( ghc . isHaLVM or false ) "all"
5757, enableSeparateDataOutput ? false
5858, enableSeparateDocOutput ? doHaddock
59- , enableSeparateBinOutput ? isExecutable
60- , outputsToInstall ? [ ]
61- , enableSeparateLibOutput ? true
62- , enableSeparateEtcOutput ? ( stdenv . lib . versionOlder "7.7" ghc . version )
6359} @ args :
6460
6561assert editedCabalFile != null -> revision != null ;
8379 then "package-db"
8480 else "package-conf" ;
8581
82+ # the target dir for haddock documentation
83+ docdir = docoutput : docoutput + "/share/doc" ;
84+
8685 newCabalFileUrl = "http://hackage.haskell.org/package/${ pname } -${ version } /revision/${ revision } .cabal" ;
8786 newCabalFile = fetchurl {
8887 url = newCabalFileUrl ;
9695 '' ;
9796
9897 hasActiveLibrary = isLibrary && ( enableStaticLibraries || enableSharedLibraries || enableLibraryProfiling ) ;
99- hasLibOutput = enableSeparateLibOutput && hasActiveLibrary ;
100- libDir = if hasLibOutput then "$lib/lib/${ ghc . name } " else "$out/lib/${ ghc . name } " ;
101- binDir = if enableSeparateBinOutput then "$bin/bin" else "$out/bin" ;
102- libexecDir = if enableSeparateBinOutput then "$libexec/bin" else "$out/libexec" ;
103- etcDir = if enableSeparateEtcOutput then "$etc/etc" else "$out/etc" ;
104- docDir = if enableSeparateDocOutput then "$doc/share/doc" else "$out/share/doc" ;
105- dataDir = if enableSeparateDataOutput then "$data/share/${ ghc . name } " else "$out/share/${ ghc . name } " ;
10698
10799 # We cannot enable -j<n> parallelism for libraries because GHC is far more
108100 # likely to generate a non-determistic library ID in that case. Further
@@ -121,20 +113,12 @@ let
121113 stdenv . lib . optionalString isCross ( " " + stdenv . lib . concatStringsSep " " crossCabalFlags ) ;
122114
123115 defaultConfigureFlags = [
124- "--verbose" "--prefix=$out"
125- # Binary directory has to be $bin/bin instead of just $bin: this
126- # is so that the package is added to the PATH when it's used as a
127- # build input. Sadly mkDerivation won't add inputs that don't have
128- # bin subdirectory.
129- "--bindir=${ binDir } "
130- "--libdir=${ libDir } " "--libsubdir=\\ $pkgid"
131- "--libexecdir=${ libexecDir } "
132- ( optionalString ( enableSeparateEtcOutput ) "--sysconfdir=${ etcDir } " ) # Old versions of cabal don't support this flag.
133- "--datadir=${ dataDir } "
134- "--docdir=${ docDir } "
116+ "--verbose" "--prefix=$out" "--libdir=\\ $prefix/lib/\\ $compiler" "--libsubdir=\\ $pkgid"
117+ ( optionalString enableSeparateDataOutput "--datadir=$data/share/${ ghc . name } " )
118+ ( optionalString enableSeparateDocOutput "--docdir=${ docdir "$doc" } " )
135119 "--with-gcc=$CC" # Clang won't work without that extra information.
136120 "--package-db=$packageConfDir"
137- ( optionalString ( enableSharedExecutables && stdenv . isLinux ) "--ghc-option=-optl=-Wl,-rpath=${ libDir } /${ pname } -${ version } " )
121+ ( optionalString ( enableSharedExecutables && stdenv . isLinux ) "--ghc-option=-optl=-Wl,-rpath=$out/lib/ ${ ghc . name } /${ pname } -${ version } " )
138122 ( optionalString ( enableSharedExecutables && stdenv . isDarwin ) "--ghc-option=-optl=-Wl,-headerpad_max_install_names" )
139123 ( optionalString enableParallelBuilding "--ghc-option=-j$NIX_BUILD_CORES" )
140124 ( optionalString useCpphs "--with-cpphs=${ cpphs } /bin/cpphs --ghc-options=-cpp --ghc-options=-pgmP${ cpphs } /bin/cpphs --ghc-options=-optP--cpp" )
168152 allPkgconfigDepends = pkgconfigDepends ++ libraryPkgconfigDepends ++ executablePkgconfigDepends ++
169153 optionals doCheck testPkgconfigDepends ++ optionals doBenchmark benchmarkPkgconfigDepends ;
170154
171- nativeBuildInputs = map stdenv . lib . getBin
172- ( optional ( allPkgconfigDepends != [ ] ) pkgconfig
173- ++ buildTools ++ libraryToolDepends ++ executableToolDepends
174- ++ [ removeReferencesTo ]
175- ) ;
155+ nativeBuildInputs = optional ( allPkgconfigDepends != [ ] ) pkgconfig ++
156+ buildTools ++ libraryToolDepends ++ executableToolDepends ++ [ removeReferencesTo ] ;
176157 propagatedBuildInputs = buildDepends ++ libraryHaskellDepends ++ executableHaskellDepends ;
177158 otherBuildInputs = setupHaskellDepends ++ extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++
178159 optionals ( allPkgconfigDepends != [ ] ) allPkgconfigDepends ++
@@ -201,15 +182,7 @@ assert allPkgconfigDepends != [] -> pkgconfig != null;
201182stdenv . mkDerivation ( {
202183 name = "${ pname } -${ version } " ;
203184
204- outputs = if ( args ? outputs ) then args . outputs else
205- ( ( optional enableSeparateBinOutput "bin" )
206- ++ ( optional enableSeparateBinOutput "libexec" )
207- ++ [ "out" ]
208- ++ ( optional enableSeparateDataOutput "data" )
209- ++ ( optional enableSeparateDocOutput "doc" )
210- ++ ( optional enableSeparateEtcOutput "etc" )
211- ++ ( optional hasLibOutput "lib" )
212- ) ;
185+ outputs = if ( args ? outputs ) then args . outputs else ( [ "out" ] ++ ( optional enableSeparateDataOutput "data" ) ++ ( optional enableSeparateDocOutput "doc" ) ) ;
213186 setOutputFlags = false ;
214187
215188 pos = builtins . unsafeGetAttrPos "pname" args ;
@@ -233,15 +206,15 @@ stdenv.mkDerivation ({
233206
234207 postPatch = optionalString jailbreak ''
235208 echo "Run jailbreak-cabal to lift version restrictions on build inputs."
236- ${ stdenv . lib . getBin jailbreak-cabal } /bin/jailbreak-cabal ${ pname } .cabal
209+ ${ jailbreak-cabal } /bin/jailbreak-cabal ${ pname } .cabal
237210 '' + postPatch ;
238211
239212 setupCompilerEnvironmentPhase = ''
240213 runHook preSetupCompilerEnvironment
241214
242215 echo "Build with ${ ghc } ."
243216 export PATH="${ ghc } /bin:$PATH"
244- ${ optionalString ( hasActiveLibrary && hyperlinkSource ) "export PATH=${ stdenv . lib . getBin hscolour } /bin:$PATH" }
217+ ${ optionalString ( hasActiveLibrary && hyperlinkSource ) "export PATH=${ hscolour } /bin:$PATH" }
245218
246219 packageConfDir="$TMPDIR/package.conf.d"
247220 mkdir -p $packageConfDir
@@ -268,7 +241,7 @@ stdenv.mkDerivation ({
268241 #
269242 # Create a local directory with symlinks of the *.dylib (macOS shared
270243 # libraries) from all the dependencies.
271- local dynamicLinksDir="${ libDir } /links"
244+ local dynamicLinksDir="$out/lib /links"
272245 mkdir -p $dynamicLinksDir
273246 for d in $(grep dynamic-library-dirs "$packageConfDir/"*|awk '{print $2}'); do
274247 ln -s "$d/"*.dylib $dynamicLinksDir
@@ -340,15 +313,15 @@ stdenv.mkDerivation ({
340313
341314 ${ if ! hasActiveLibrary then "${ setupCommand } install" else ''
342315 ${ setupCommand } copy
343- local packageConfDir="${ libDir } /package.conf.d"
316+ local packageConfDir="$out/lib/ ${ ghc . name } /package.conf.d"
344317 local packageConfFile="$packageConfDir/${ pname } -${ version } .conf"
345318 mkdir -p "$packageConfDir"
346319 ${ setupCommand } register --gen-pkg-config=$packageConfFile
347320 local pkgId=$( ${ gnused } /bin/sed -n -e 's|^id: ||p' $packageConfFile )
348321 mv $packageConfFile $packageConfDir/$pkgId.conf
349322 '' }
350323 ${ optionalString isGhcjs ''
351- for exeDir in "${ binDir } /"*.jsexe; do
324+ for exeDir in "$out/bin /"*.jsexe; do
352325 exe="'' ${exeDir%.jsexe}"
353326 printWords '#!${ nodejs } /bin/node' > "$exe"
354327 cat "$exeDir/all.js" >> "$exe"
@@ -357,68 +330,18 @@ stdenv.mkDerivation ({
357330 '' }
358331 ${ optionalString doCoverage "mkdir -p $out/share && cp -r dist/hpc $out/share" }
359332 ${ optionalString ( enableSharedExecutables && isExecutable && ! isGhcjs && stdenv . isDarwin && stdenv . lib . versionOlder ghc . version "7.10" ) ''
360- for exe in "${ binDir } /"* ; do
361- install_name_tool -add_rpath "${ libDir } /${ pname } -${ version } " "$exe"
333+ for exe in "$out/bin /"* ; do
334+ install_name_tool -add_rpath "$out/lib/ghc- ${ ghc . version } /${ pname } -${ version } " "$exe"
362335 done
363336 '' }
364337
365338 ${ optionalString enableSeparateDocOutput ''
366- # Remove references back to $out but also back to $lib if we have
367- # docs. $lib is needed as it stores path to haddock interfaces in the
368- # conf file which creates a cycle if docs refer back to library
369- # path.
370- mkdir -p ${ docDir }
371-
372- for x in ${ docDir } /html/src/*.html; do
373- remove-references-to -t $out -t ${ libDir } -t ${ binDir } ${ optionalString enableSeparateDataOutput "-t $data" } $x
339+ for x in ${ docdir "$doc" } /html/src/*.html; do
340+ remove-references-to -t $out $x
374341 done
342+ mkdir -p $doc
375343 '' }
376-
377- ${ optionalString hasLibOutput ''
378- # Even if we don't have binary output for the package, things like
379- # Paths files will embed paths to bin/libexec directories in themselves
380- # which results in .lib <-> $out cyclic store reference. We
381- # therefore patch out the paths from separate library if we don't have
382- # separate bin output too.
383- #
384- # If we _do_ have separate bin and lib outputs, we may still be in
385- # trouble in case of shared executables: executable contains path to
386- # .lib, .lib contains path (through Paths) to .bin and we have a
387- # cycle.
388- #
389- # Lastly we have to deal with references from .lib back into
390- # $out/share if we're not splitting out data directory.
391- #
392- # It may happen that we have hasLibOutput set but the library
393- # directory was not created: this happens in the case that library
394- # section is not exposing any modules. See "fail" package for an
395- # example where no modules are exposed for GHC >= 8.0.
396- if [ -d ${ libDir } ]; then
397- find ${ libDir } -type f -exec \
398- remove-references-to -t ${ binDir } -t ${ libexecDir } "{}" \;
399- fi
400- '' }
401-
402- ${ optionalString ( hasLibOutput && ! enableSeparateDocOutput ) ''
403- # If we don't have separate docs, we have to patch out the ref to
404- # docs in package conf. This will likely break Haddock
405- # cross-package links but is necessary to break store cycle…
406- find ${ libDir } / -type f -name '*.conf' -exec \
407- remove-references-to -t ${ docDir } "{}" \;
408- '' }
409-
410- ${ optionalString ( hasLibOutput && ! enableSeparateDataOutput ) ''
411- # Just like for doc output path in $out potentially landing in
412- # *.conf, we have to also remove the data directory so that it
413- # doesn't appear under data-dir field creating a cycle.
414- find ${ libDir } / -type f -exec echo Removing ${ dataDir } refs from "{}" \;
415- find ${ libDir } / -type f -exec \
416- remove-references-to -t ${ dataDir } "{}" \;
417- '' }
418-
419- ${ optionalString enableSeparateDataOutput "mkdir -p ${ dataDir } " }
420- ${ optionalString enableSeparateBinOutput "mkdir -p ${ binDir } ${ libexecDir } " }
421- ${ optionalString enableSeparateEtcOutput "mkdir -p ${ etcDir } " }
344+ ${ optionalString enableSeparateDataOutput "mkdir -p $data" }
422345
423346 runHook postInstall
424347 '' ;
@@ -435,7 +358,7 @@ stdenv.mkDerivation ({
435358 # the directory containing the haddock documentation.
436359 # `null' if no haddock documentation was built.
437360 # TODO: fetch the self from the fixpoint instead
438- haddockDir = self : if doHaddock then "${ docDir } /html" else null ;
361+ haddockDir = self : if doHaddock then "${ docdir self . doc } /html" else null ;
439362
440363 env = stdenv . mkDerivation {
441364 name = "interactive-${ pname } -${ version } -environment" ;
@@ -463,7 +386,6 @@ stdenv.mkDerivation ({
463386 // optionalAttrs ( description != "" ) { inherit description ; }
464387 // optionalAttrs ( maintainers != [ ] ) { inherit maintainers ; }
465388 // optionalAttrs ( hydraPlatforms != platforms ) { inherit hydraPlatforms ; }
466- // optionalAttrs ( outputsToInstall != [ ] ) { inherit outputsToInstall ; }
467389 ;
468390
469391}
0 commit comments