How to push my Haskell Stack build to Cachix

I made some backend using Stack.

My Stack project succeeds when I do stack build --nix and it seems to create a nix package in local project cache directory in which executable is built. ( .stack-work/install/x86_64-osx-<some sha1> )

How can I cache it on Cachix? Cachix docs says do nix-build | cachix push but I can’t because I’m using stack build instead.

FYI my ultimate goal is to run it on AWS and deliver the package via Cachix.

As it looks like you’ve figured out, doing stack build --nix builds your Haskell dependencies with stack and not Nix. You’re not able to push your Haskell dependencies to Cachix if you’ve built them with Stack.

I summed up some of the ways to build a Haskell project with Nix in this post:

The things that would be compatible with pushing to cachix are shellFor from Nixpkgs, and using haskell.nix.

If you wanted to be able to use both stack build --nix and nix-build (while using stack.yaml as a single-source-of-truth), then currently haskell.nix is your only option. Although shellFor from Nixpkgs is somewhat simpler, and may be easier if you are just starting out with Nix.

1 Like
Hosted by Flying Circus.