@@ -179,6 +179,10 @@ stdenv.mkDerivation ({
179179 # The directory containing the haddock documentation.
180180 # `null' if no haddock documentation was built.
181181 haddockDir = if doHaddock' then "${ docdir drv . doc } /html" else null ;
182+ } // lib . optionalAttrs isDoctest {
183+ # We could not figure out how to have separate `source` and `dist` outputs
184+ # for doctest as it results in a circular references.
185+ source = drv ;
182186 } ;
183187
184188 meta = {
@@ -213,8 +217,7 @@ stdenv.mkDerivation ({
213217 outputs = [ "out" ]
214218 ++ ( lib . optional enableSeparateDataOutput "data" )
215219 ++ ( lib . optional doHaddock' "doc" )
216- ++ ( lib . optional keepSource "source" )
217- ++ ( lib . optional isDoctest "dist" ) ;
220+ ++ ( lib . optional ( keepSource && ! isDoctest ) "source" ) ;
218221
219222 # Phases
220223 preInstallPhases = lib . optional doHaddock' "haddockPhase" ;
@@ -226,7 +229,12 @@ stdenv.mkDerivation ({
226229 '' ;
227230
228231 configurePhase =
229- ( lib . optionalString keepSource ''
232+ ( lib . optionalString isDoctest ''
233+ cp -r . $out
234+ cd $out
235+ chmod -R +w .
236+ '' ) +
237+ ( lib . optionalString ( keepSource && ! isDoctest ) ''
230238 cp -r . $source
231239 cd $source
232240 chmod -R +w .
@@ -354,9 +362,7 @@ stdenv.mkDerivation ({
354362 '' )
355363 }
356364 runHook postInstall
357- '' + ( lib . optionalString isDoctest ''
358- cp -r dist/ $dist/
359- '' ) + ( lib . optionalString keepSource ''
365+ '' + ( lib . optionalString ( keepSource && ! isDoctest ) ''
360366 rm -rf dist
361367 '' ) ;
362368
0 commit comments