dfadcb0 Update cabal-plan tools to latest state of cabal pr
~fgaz pushed to ~fgaz/nix-build-cabal-project git
Alternative Haskell Nix infrastructure based on cabal and fixed-output derivations
Like
buildRustPackageandbuildGoModule, but for Haskell!
First of all, add a freeze file to your cabal project (cabal freeze). The minimal structure for a buildCabalProject-based project is the following:
import /path/to/nix-build-cabal-project {} { pname = "example"; version = "0.1.0.0"; src = ./example; dependenciesHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; } This will build all the executables in the example project. To choose which executables to build, you can pass a list of string as target parameter.
While nix-build-cabal-project is mainly intended for deployment, it is possible to make cabal use the dependencies built by nix.
cabalStore attribute of your packagecabal, use either: --store-dir result, more robust but less flexible (you'll have a read-only store!).--package-db result/ghc-*/package.db, more flexible but less robust (there's a note in default.nix if you want the gory details). If it works, you should prefer this.TODO: provide a wrapped ghc and cabal that always use the cached store
You will receive an alert if you need to update the hash.
This will happen when there are changes to the freeze file or to the targets.
If you use a solver-based build, the hash will also change when one of the following changes:
For this reason, it's recommended to pin the ghc and possibly cabal version.
Projects without freeze files can also be built, since cabal's solver is deterministic. Simply pass an indexState attribute (eg. indexState = "2021-03-08T20:01:13Z";) and delete any existing freeze files, and cabal will do the dependency resolution.
Non-Haskell dependencies (eg. zlib, pkg-config) can simply be added to buildInputs and nativeBuildInputs
You can build specific cabal targets by passing the targets attribute, eg. targets = [ "myexe1" "myexe2" ];.
Use doCheck as usual. You can pass a list of strings as test parameter to choose which tests to run.
You can send patches to my public-inbox mailing list or to any of the contacts listed at fgaz.me/about. Or you can send a pull request to the Codeberg mirror.
Issues are tracked at https://todo.sr.ht/~fgaz/nix-build-cabal-project
There are other projects with similar objectives, and this one may not be the best for your needs. For example, it is not suitable if you need to cache dependencies individually. On the other hand, it works well if you want a simple FOD-based build like nixpkgs.rustPlatform.buildRustPackage. Here is a comparison with other projects:
nixpkgs.haskellPackages is the Haskell infrastructure used in nixpkgs. callCabal2nix.callCabal2nix.haskell.nix is IOHK's Haskell infrastructure. plan-to-nix manually.plan-to-nix manually.