Last active
February 22, 2016 17:57
-
-
Save aaronlevin/2592deae23c54f4c1712 to your computer and use it in GitHub Desktop.
Local/Project-based Environment Management Using Nix (with new Haskell NG infrastructure)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; | |
} |
note: this actually doesn't work.
this now works.
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
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 toshell.nix