Skip to content

Instantly share code, notes, and snippets.

@aaronlevin
Last active February 22, 2016 17:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronlevin/2592deae23c54f4c1712 to your computer and use it in GitHub Desktop.
Save aaronlevin/2592deae23c54f4c1712 to your computer and use it in GitHub Desktop.
Local/Project-based Environment Management Using Nix (with new Haskell NG infrastructure)
# Inspired by:
# http://stackoverflow.com/questions/29033580/how-do-i-use-the-new-haskell-ng-infrastructure-on-nixos
#
# The goal
#
# 1. my-project.cabal remains the source of required libraries/packages to build the project.
# Adding a new library involves updating my-project.cabal and then running cabal2nix . > 02-my-project.nix
#
# 2. ability to add non-haskell build / dev dependencies to our `shell.nix` that are not used at runtime.
# For example, maybe we want to use postgresql or redis during development.
#
# 3. support local, non-hackage packages. we can follow ocharles' lead ala
# http://stackoverflow.com/questions/27968909/how-to-get-cabal-and-nix-work-together
#
# to work on the project: nix-shell 01-shell.nix
{ nixpkgs ? (import <nixpkgs> {}) }:
let
lib = nixpkgs.haskell-ng.lib;
haskell = nixpkgs.haskellngPackages.override {
overrides = self: super: {
# overrides here
# local-common-lib is not on hackage, but is a dependency for my-project
local-common-lib = self.callPackage ../local-common-lib/local-common-lib.nix {};
# we override `my-project` to add dev/build dependencies
# note that because we use `self.callPackage` self will have local-common-lib.
my-project = lib.addBuildTools (self.callPackage ./02-my-project.nix {}) [
# haskell-related build/dev tools
self.cabal-install
self.ghc-mod
# non-haskell-related build/dev tools
nixpkgs.postgresql
];
};
};
in
haskell.my-project.env
# generated using haskell-ng's cabal2nix
{ mkDerivation, base, either, free, mtl, stdenv }:
mkDerivation {
pname = "my-project";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
buildDepends = [ base either free mtl ];
license = stdenv.lib.licenses.unfree;
}
@aaronlevin
Copy link
Author

some historical context for the three people out there reading this: my previous work flow involved adding dependencies to my-project.cabal and then having to manually add them to shell.nix

@aaronlevin
Copy link
Author

note: this actually doesn't work.

@aaronlevin
Copy link
Author

this now works.

@aaronlevin
Copy link
Author

edit: used lib.addBuildTools instead of cabalOverride. How did I miss that?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment