RFC: Nix support for running Haskell plugins

#1

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: https://github.com/mpickering/haskell-nix-plugin

Questions:

  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?

Cheers,

Matt

1 Like

#2

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.

0 Likes