jonascarpay / template-haskell

batteries-included nix-based haskell project template
BSD 3-Clause "New" or "Revised" License
61 stars 10 forks source link

[Question] Dependency Management #18

Closed Burtannia closed 2 months ago

Burtannia commented 2 months ago

Hey, thanks for creating this repo.

I'm new to nix and NixOS so just had a couple of questions regarding Haskell on nix.

How does dependency management work? The nix develop shell includes cabal but can we use cabal update and cabal gen-bounds as usual?

If we add dependency versions in our cabal file, does it work? I tried adding containers == 0.7 (which matches the version in nixpkgs) to the template but running nix develop gives me:

> Error: Setup: Encountered missing or private dependencies:
> containers ==0.7

A bit of guidance on what the best practices are with Haskell/nix when it comes to dependency versions would be much appreciated.

jonascarpay commented 2 months ago

Your dependencies come directly from nixpkgs, and (like stack LTS'es) nixpkgs pins the package versions for you. Unless you're publishing to hackage, there's usually no need to specify/worry about versions yourself, the versions in nixpkgs usually just work together. If you want to update, nix flake update updates all packages in lockstep. cabal update is for when cabal manages your dependencies, which we don't want.

If the version bounds in your cabal file conflict with the versions in nixpkgs, you get the above error. If bumping nixpkgs/dropping version bounds is not an option, there are ways to inject a different version of a package into nixpkgs, see here, specifically the part about callHackageDirect.

Burtannia commented 2 months ago

Thanks :)