Recently I implemented some support for running Haskell plugins conveniently using nix.
Plugins can be used to extract information from packages or modify the programs. They run at certain stages of the compilation and more possibilities will be added in GHC 8.6. For example, the dump-core
plugin extracts the compiler intermediate representation (core) and renders it as HTML.
I find myself often wanting to run plugins on packages but it is inconvenient to do so without modifying the cabal file. So I added some nix magic which makes things much more convenient. For example:
let
plugin-overlay-git = builtins.fetchGit
{ url = https://github.com/mpickering/haskell-nix-plugin.git;} ;
plugin-overlay = import "${plugin-overlay-git}/overlay.nix";
nixpkgs = import <nixpkgs> { overlays = [plugin-overlay]; };
hl = nixpkgs.haskell.lib;
hp = nixpkgs.haskellPackages;
in
(hp.withPlugin(plugs: ps: hl.addPlugin plugs.dump-core ps.either)).DumpCore
Blog Post: http://mpickering.github.io/posts/2018-06-24-haskell-nix-plugins.html
Code: GitHub - mpickering/haskell-nix-plugin: Plugin scaffolding for nixpkgs
Questions:
- Is this support desirable to be upstreamed or should I keep it in an overlay?
- Are there any improvements I can make to the API? In particular, plugins and packages have to be compiled with the same compiler or the errors will be quite obtuse. The
withPlugin
function is meant to help with this. - Is this useful for anyone else?
Cheers,
Matt