[Nix-dev] nix-shell for a custom haskell library
Peter Jones
mlists at pmade.com
Mon Jun 1 21:25:31 CEST 2015
Dmitry Malikov <malikov.d.y at gmail.com> writes:
> I'm trying to setup a development environment for a custom haskell library
> basing on a tutorial by Oliver Charles
> (http://wiki.ocharles.org.uk/Nix).
FWIW I've been playing with Nix and Haskell a lot lately trying to come
up with the perfect development environment. This is what I have so
far. Everything below is done with a recent copy of nixpkgs.
I have a shell function called nix-hs-build that does the following:
# Create a default.nix for the Haskell project in $PWD:
nix-shell -p haskellPackages.cabal2nix \
--command "cabal2nix $PWD $@ > default.nix"
# Build the project:
nix-hs-shell --command $(which hsbuild.sh) "$@"
The contents of hsbuild.sh can be found here:
https://gist.github.com/pjones/7a6023d3567ff2ed49bf
The `nix-hs-shell` command is another shell function that just runs
nix-shell with cabal-install and hlint in the environment so that
hsbuild.sh can work. Here are the details:
function nix-hs-shell () {
override=~/.nixpkgs/envs/dev/haskell-cabal.nix
nix-shell -I pwd=$PWD --pure "$@" $override
}
Where haskell-cabal.nix contains:
{ nixpkgs ? import <nixpkgs> {}
, compiler ? "ghc7101"
}:
let
pkgs = nixpkgs.pkgs;
ghc = pkgs.haskell.packages.${compiler};
f = import <pwd>;
drv = ghc.callPackage f {};
in
(pkgs.haskell.lib.addBuildTools drv [
ghc.cabal-install
ghc.hlint
]).env
With those pieces I can just run `nix-hs-build` without having to create
any sort of *.nix file by hand. If I change the project's cabal file
and run `nix-hs-build` it will work since it generates the default.nix
again. I can also change compilers with a flag:
nix-hs-build --compiler ghc784
> How to get Network.EngineIO available inside a nix-shell in this case?
Using my setup above, the library would be installed in ./dist
--
Peter Jones, Founder, Devalot.com
Defending the honor of good code
--
Peter Jones, Founder, Devalot.com
Defending the honor of good code
More information about the nix-dev
mailing list