I’m sharing here how you can apply a patch to GHC from within your project, so that next time I forget it, I can find it.
Of course you could fork nixpkgs and update patches =
in the ghc derivation like this one but sometimes you want to patch only the GHC used in your project, not for all of nixpkgs (e.g. you don’t care about your patch applying to pandoc
and thus rebuilding half of nixpkgs).
How to:
Use this (e.g. in your overlay or other nix configuration):
haskellPackages = with pkgs.haskell.lib; pkgs.haskell.packages.ghc865.override (oldHaskellPackages: {
# Override the ghc here:
overrides = lib.composeExtensions (oldHaskellPackages.overrides or (_: _: {})) (self: super: {
patches = (old.patches or []) ++ [
(pkgs.fetchpatch {
url = "https://gitlab.haskell.org/nh2/ghc/-/commit/766ae0129dadd677d5ab500c2af8d5d747761ac4.patch";
name = "ghc-Add-RTS-disable-delayed-os-memory-return.patch";
sha256 = "0p46g1315kgg8v4gv29cni9rm9b2nbjcpg0qaf5sr6yarwaq7k47";
})
];
});
overrides = self: super: {
# Haskell package overrides go in here
cryptonite = overrideCabal super.cryptonite (old: {
src = ...;
});
});
});
The line
lib.composeExtensions (oldHaskellPackages.overrides or (_: _: {}))
is long and ugly, but it is currently the correct boilerplate way to ensure to not accidentally remove the effects of previous overlays, as is explained in https://github.com/NixOS/nixpkgs/issues/26561#issuecomment-397350884.