From 40bb2781eeb73ec01d167d96c810f43deb240a7e Mon Sep 17 00:00:00 2001
From: Peter Simons <simons@cryp.to>
Date: Thu, 6 Nov 2014 14:05:44 +0100
Subject: [PATCH] cabal: add "-hidir $TMPDIR" parameter to ghc call that
 compiles Setup.hs

Packages that don't have a Setup.hs file get to use a default version that
lives in the Nix store. By default ghc tries to put the Setup.o and Setup.hi
files in the same directory as the source file, which isn't writable. This
leads to build errors [1]. Thus, we re-direct those paths to a build-local
writable location: $TMPDIR.

Arguably, we could also use "." or copy the /nix/store/deadbeef-Setup.hs file
into the local source directory before compiling, which would work fine, too.

[1] https://github.com/NixOS/nixpkgs/issues/4851
---
 pkgs/build-support/cabal/default.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkgs/build-support/cabal/default.nix b/pkgs/build-support/cabal/default.nix
index 3fa833876921..e9a8a50774c9 100644
--- a/pkgs/build-support/cabal/default.nix
+++ b/pkgs/build-support/cabal/default.nix
@@ -194,7 +194,7 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
               for i in Setup.hs Setup.lhs ${defaultSetupHs}; do
                 test -f $i && break
               done
-              ghc --make -o Setup -odir $TMPDIR $i
+              ghc --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
 
               for p in $extraBuildInputs $propagatedNativeBuildInputs; do
                 if [ -d "$p/lib/ghc-${ghc.ghc.version}/package.conf.d" ]; then