Skip to content

Instantly share code, notes, and snippets.

@joamaki
Created September 23, 2014 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joamaki/1ed34dfe8977995bad72 to your computer and use it in GitHub Desktop.
Save joamaki/1ed34dfe8977995bad72 to your computer and use it in GitHub Desktop.
# modification in cabal build support:
for i in Setup.hs Setup.lhs; do
test -f $i && \
${if buildSetupWithBareGhc
then "${ghc.ghc}/bin/ghc"
else "ghc"} --make $i
# ...
# In project's default.nix:
let self = _self;
ghc = pkgs.haskellPackages_ghc763.ghc;
myCabal =
let
preCabal = pkgs.callPackage ./cabal {
inherit ghc;
Cabal = null;
jailbreakCabal = null;
# Some tests require GHC API which we can't use
# because of bytestring version mismatch.
enableCheckPhase = false;
# Split objs help with executable size, but slow down the build
# quite a lot.
enableSplitObjs = false;
buildSetupWithBareGhc = true;
};
# Wraps mkDerivation with extra dependencies.
mkDerivationWithDeps = cabal: deps: args:
cabal.mkDerivation (self:
let orig = args self;
in (orig // {
buildDepends = (pkgs.lib.maybeAttr "buildDepends" [] orig) ++ deps;
}));
# Imports a package with extra injected dependencies.
callWithDeps = deps: pkg: args:
let cabal = { mkDerivation = mkDerivationWithDeps preCabal deps; };
in import pkg (args // { inherit cabal; });
#####
# Newer version of bytestring and the packages that depend on it.
bytestring = callWithDeps [] ./bytestring {
deepseq = null;
};
binary = callWithDeps [bytestring] ./binary {};
unix = callWithDeps [bytestring binary] ./unix {
time = null;
};
directory = callWithDeps [bytestring binary unix] ./directory {
time = null;
filepath = null;
};
process = callWithDeps [bytestring binary unix directory] ./process {
filepath = null;
deepseq = null;
};
hpc = callWithDeps [bytestring binary unix directory process] ./hpc {
time = null;
};
Cabal = callWithDeps [bytestring binary unix directory process] ./Cabal {
deepseq = null;
filepath = null;
time = null;
};
jailbreakCabal = callWithDeps [bytestring binary unix directory process] ./jailbreakCabal {
inherit Cabal;
};
####
properCabal = preCabal.override {
buildSetupWithBareGhc = false;
inherit Cabal jailbreakCabal;
};
in {
inherit Cabal;
# Return a mkDerivation that forces dependency on the overriden
# base packages.
mkDerivation = mkDerivationWithDeps properCabal
[ bytestring unix directory process hpc ];
};
callPackage = pkgs.lib.callPackageWith
(self.packages // { cabal = myCabal; });
_self = with self;
{
myPackage = callPackage ./my-package {};
}
@joamaki
Copy link
Author

joamaki commented Sep 23, 2014

Oh and obviously you'll need to build all the other libraries here that your project depend with the modified cabal function.

@Pitometsu
Copy link

Pitometsu commented Jun 25, 2016

@joamaki nice solution. But too complicated for me. I'm trying do similar thing, to override Cabal from core packages in ghc7103 in lts-5_15.
NixOS/nixpkgs#3822 (comment) but can't do it right.

Need it to solve linking problem in stack bundle commercialhaskell/stack#2282 (comment)

Could you help me with solution, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment