@@ -31,6 +31,7 @@
3131, doHaddock ? component.doHaddock # Enable haddock and hoogle generation
3232, doHoogle ? component.doHoogle # Also build a hoogle index
3333, hyperlinkSource ? component.doHyperlinkSource # Link documentation to the source code
34+, keepSource ? component.keepSource # Build from `source` output in the store then delete `dist`
3435
3536# Profiling
3637, enableLibraryProfiling ? component.enableLibraryProfiling
@@ -189,7 +190,8 @@ stdenv.mkDerivation ({
189190
190191 outputs = ["out" ]
191192 ++ (lib.optional enableSeparateDataOutput "data")
192− ++ (lib.optional doHaddock' "doc");
193+ ++ (lib.optional doHaddock' "doc")
194+ ++ (lib.optional keepSource "source");
193195
194196 # Phases
195197 preInstallPhases = lib.optional doHaddock' "haddockPhase";
@@ -200,7 +202,12 @@ stdenv.mkDerivation ({
200202 ${buildPackages.haskell-nix.haskellPackages.hpack.components.exes.hpack}/bin/hpack
201203 '';
202204
203− configurePhase = ''
205+ configurePhase =
206+ (lib.optionalString keepSource ''
207+ cp -r . $source
208+ cd $source
209+ chmod -R +w .
210+ '') + ''
204211 runHook preConfigure
205212 echo Configure flags:
206213 printf "%q " ${finalConfigureFlags}
@@ -322,7 +329,9 @@ stdenv.mkDerivation ({
322329 '')
323330 }
324331 runHook postInstall
325− '';
332+ '' + (lib.optionalString keepSource ''
333+ rm -rf dist
334+ '');
326335
327336 shellHook = ''
328337 export PATH="${shellWrappers}/bin:$PATH"