RFC: Nix support for running Haskell plugins

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:

  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;
  (hp.withPlugin(plugs: ps: hl.addPlugin plugs.dump-core ps.either)).DumpCore

Blog Post: Nix scaffolding for running Haskell plugins
Code: GitHub - mpickering/haskell-nix-plugin: Plugin scaffolding for nixpkgs


  1. Is this support desirable to be upstreamed or should I keep it in an overlay?
  2. 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.
  3. Is this useful for anyone else?




This would make plugins easier to access: I haven’t tried using them ever, but this makes it look easy to do. :slight_smile:

Just one note: the name ‘Haskell plugin’ made me think you were talking about code compiled from Haskell being used as a plugin. (Maybe with some XMonad-y recompilation happening? I clicked through to this post because I was confused and intrigued.) It seems like these are really GHC plugins, and should be called such.