I tried using yesod devel to spin up a development server. However stack (yesod devel calls stack) will attempt to build all (or at least a lot of the) dependencies, even if I am in a nix-shell that provides those. Running nix-build works as expected and uses the binary cache.
How can I tell stack to use the dependencies provides by Nix?
When using stack with nix I use a resolver like ghc-8.6.5. This causes stack to use the package db that nix provides for you. I think there are several ways to get stack to use a particular resolver, and I am not sure what the easiest is for you (i.e. a user configured default resolver, the resolver set in a stack yaml, or the --resolver flag passed directly to stack).
Just using the resolver ghc-8.6.5 does not work for me. After throwing many extra-deps into stack.yaml it starts compiling again. Maybe I need to use buildStackProject. I will certainly try this.
That’s the downside of using the ghc-8.6.5 approach. You have to manually get dependencies from nix through the stack-shell.nix file.
It takes away a lot of the benefit of using stack, in my opinion.
In general, if you’re using stack and one of the LTS/nightly resolvers, there is no way to get Haskell dependencies from nix. The blog post linked above explains this.
I hope to give the stack-shell.nix-approach a go today. To be honest, I do not want to use stack in the first place. However yesod devel uses stack internally and I do want to use the development server provided by yesod devel.
You would use cabal2nix to generate a default.nix that enumerates your dependencies. Then you would have a shell.nix that imports that derivation. In a shell built from that shell.nix, stack with a ghc-8.6.5 resolver would find all the required dependencies in the package db nix provides for you.
I did this for a while when using intero for editor tooling which also wants to continually reload everything into a running ghci process.