Home

Awesome

haskell-overridez CircleCI

haskell-overridez is a script and library of nix functions that simplify the use of overrides while developing haskell projects with nixpkgs.

Inspiration

haskell-overridez is inspired by the section on Advanced Dependency Management in haskell-nix. The idea is to turn the recommendations there into a tool that is itself installed into the nix environment.

Installation

It's assumed that you have already installed nix.

You can then install haskell-overridez using nix-env:


nix-env --install -f https://github.com/adetokunbo/haskell-overridez/archive/master.tar.gz

Usage

Installation adds the command haskell-overridez to the nix environment.

It is a wrapper script around other tools whose output it writes to subdirectories of the development project.

E.g,

$ cd my-nix-project

# install an override using github json
$ haskell-overridez -g reflex-frp/reflex-dom-contrib

# install an override using cabal2nix
$ haskell-overridez https://github.com/tathougies/beam --subpath beam-core

There various options for managing the overrides; to see them all, you can read the usage:

$ haskell-overridez -h
haskell-overridez - manage nix overrides for haskell packages
...

Project Layout

Given the example commands above, haskell-overridez creates a project with the following layout:

├── default.nix
│
├── nix (1)
│   │
│   ├── haskell-overridez.nix (2)
│   │
│   ├── nix-expr (3)
│   │   └── beam-core.nix
│   │
│   ├── git-json (3)
│   │   └── reflex-dom-contrib.json
  1. There is a nix subdirectory of the main project directory.
  2. There is a haskell-overridez.nix file that contains the nix expression used to load the accompanying nix expression library.
  3. There are subdirectories (nix-expr, git-json) that contain the output from the tools.
  4. The accompanying library functions use the contents of the subdirectories to generate a nix expression that combines all the overrides into a single nix overlay.

Using the library functions

The library functions can be used from default.nix as follows:


let
  overridez = import ./nix/haskell-overridez.nix;
  config = {
    packageOverrides = pkgs: {
      haskellPackages = pkgs.haskellPackages.override {
        overrides = overridez.allIn ./nix;
      };
    };
  };
  pkgs = import <nixpkgs> { inherit config; };

in
  {}

Some overrides can't be specified using haskell-overridez and will need to be specified in other ways. The two sets can be combined using combineAllIn instead of allIn:


let
  overridez = import ./nix/haskell-overridez.nix;
  myManualOverride = self: super: {};
  myImportedOverrides = import /from/some/nix/file.nix;

  config = {
    packageOverrides = pkgs: {
      haskellPackages = pkgs.haskellPackages.override {
        overrides = overridez.combineAllIn ./nix [myManualOverride myImportedOverrides];
      };
    };
  };
  pkgs = import <nixpkgs> { inherit config; };

in
  {}


Using the library functions in reflex-project-skeleton projects

Projects developed using the Reflex Platform can benefit from adopting the layout in reflex-project-skeleton. This allows them to share haskell code between frontend and backend. In these projects, haskell-overridez can be used as follows:


let pkgs = import <nixpkgs> {};
    overridez = import ./nix/haskell-overridez.nix;
in

{}:

(import ../../repos/reflex-platform {}).project ({ pkgs, ... }: {
  packages = {
    common = ./common;
    backend = ./backend;
    frontend = ./frontend;
  };

  shells = {
    ghc = ["common" "backend" "frontend"];
    ghcjs = ["common" "frontend"];
  };

  overrides = overridez.allIn ./nix;
})

Contributions

Contributions are welcome! Please raise an issue to report any problems or open a PR with fixes and improvements.

Road Map

  1. Ask people to try it out to see if its useful (.. soonish)
  2. Iterate on its features to make more useful (.. going forward)
  3. (??) Merge it into nixpkgs (later, if people think that's a good idea)

License

BSD-3 clause