[Nix-dev] [Nix-Dev] Packaging a Haskell project using Stack

Sergey Mironov grrwlf at gmail.com
Tue Jan 10 11:20:29 CET 2017


>> I am to package Stack project which
>>
>>   1) depends on old lts-2.21 package set from stackage
>>   2) doesn't have .cabals anymore, only .yamls.
>>
>> The question is basically How to do it?
>
> Run "hpack" to generate the Cabal files. Then run "cabal2nix" to
> generate the Nix files. Add those Nix builds to Nixpkgs as explained in
> the user's manual at:
>
>   http://nixos.org/nixpkgs/manual/#how-to-create-nix-builds-for-your-own-private-haskell-packages
>

OK, I've managed to create a prototype nix-shell script to packaging
(not simply building) dependencies for a Stack project. Parameters are
explained in its header.

https://github.com/grwlf/nixcfg/blob/unstable/ideas/unstack.sh

It works by
1) Calling stack list-dependencies
2) Calling cabal2nix for every dependency
3) Producing top-level all.nix expression

The script is not for end-users yet, it doesn't produce final
expression to build the Stack project, only its dependencies. Also,
small modification of  pkgs/development/haskell-modules/default.nix is
required: One should replace line `inherit mkDerivation callPackage;`
with `inherit mkDerivation callPackage callPackageWithScope;`. Thus,
callPackageWithScope function will be accessible for the script.

Regards,
Sergey


More information about the nix-dev mailing list