Nix library to run weeder on haskell projects built with haskell.nix
Go to file
2020-06-23 07:44:53 +03:00
LICENCES Add license and promo blurb 2020-01-15 08:12:49 +03:00
default.nix Allow overriding weeder package 2020-06-23 07:44:53 +03:00
LICENSE Add license and promo blurb 2020-01-15 08:12:49 +03:00
README.md Add license and promo blurb 2020-01-15 08:12:49 +03:00
weeder-script.nix Allow overriding weeder package 2020-06-23 07:44:53 +03:00

A bunch of hacks making weeder work for projects built with haskell.nix

Usage example

Suppose you have a project with three packages in a layout like this (note that package name and directory name may differ):

super-project
|-- stack.yaml
|-- super-package.cabal
|-- …
|-- prelude
    |-- super-prelude.cabal
    |-- …
|-- super-tool
    |-- super-tool.cabal
    |-- …

Import this library, providing nixpkgs package set:

weeder-hacks = import (builtins.fetchTarball https://github.com/serokell/haskell-nix-weeder/archive/master.tar.gz) { pkgs = import <nixpkgs> {}; };

In the call to haskell-nix.stackProject add options for each package to generate .dump-hi files used by weeder and save them to the build output:

hs-pkgs = haskell-nix.stackProject {
  
  modules = [{
    packages.super-package = {
      # tell the compiler to generate '.dump-hi' files
      package.ghcOptions = "-ddump-to-file -ddump-hi";

      # save '.dump-hi' files to $out
      postInstall = weeder-hacks.collect-dump-hi-files;
    };

    packages.super-prelude = {
      package.ghcOptions = "-ddump-to-file -ddump-hi";
      postInstall = weeder-hacks.collect-dump-hi-files;
    };

    packages.super-tool = {
      package.ghcOptions = "-ddump-to-file -ddump-hi";
      postInstall = weeder-hacks.collect-dump-hi-files;
    };
  }];
};

Invoke weeder-script derivation which generates a script for running weeder. Provide hs-pkgs and local-packages parameters:

weeder-script = weeder-hacks.weeder-script {
  # package set returned by `haskell-nix.stackProject`
  hs-pkgs = hs-pkgs;

  # names and subdirectories of local packages
  local-packages = [
    { name = "super-package"; subdirectory = "."; }
    { name = "super-prelude"; subdirectory = "prelude"; }
    { name = "super-tool"; subdirectory = "super-tool"; }
  ];
};

Run nix-build on the weeder-script derivation to generate the script, running the script will run weeder. Note that running the script will copy '.dump-hi' files locally, polluting your local directory.

$ nix-build -A weeder-script -o run-weeder.sh  # generates the script
$ ./run-weeder.sh  # runs weeder

About Serokell

This library is maintained and funded with ❤️ by Serokell. The names and logo for Serokell are trademark of Serokell OÜ.

We love open source software! See our other projects or hire us to design, develop and grow your idea!