-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve stack workflow/UX with haskell.nix #689
Comments
The problem is that if you're already inside of a nix-shell which provides all the libraries stack needs you need to disable stack's own nix integration like: [nix-shell:~/code/tmp/haskell-nix-stack-workflow]$ stack --stack-yaml stack-nix.yaml --no-nix ghci |
So things work very well and seem to be seamless as of this working tree. |
I've also updated now my comment on commercialhaskell/stack#3617 (comment) to include the |
maybe relevant: @cdepillabout devised a stack+nix workflow for hasktorch, see this PR: hasktorch/hasktorch#382 |
@tscholak Thanks! From a super quick glance, I think that uses stack's nix integration whereas this method circumvents and turns off stack's nix integration. Perhaps when @cdepillabout get's time they will have useful comments on their approach vs ours 🙂 . |
@tscholak Maybe I didn't quite understand the original message, but why would you turn off In my experience it works pretty well, and it doesn't require you to jump into a The solution in hasktorch/hasktorch#382 is the same approach we've been using at work as well for a while now, and it seems to work alright (aside from the various problems of using stack with nix). |
Basically to use it as a "dumb" interface to the packages nix has already put in place.
I recall having at least one issue with the stack nix integration (will have to search my notes) and it seemed better to lean more on nix than stack's nix integration. I think it's also closer to how the cabal integration works, but that's only a feeling.
Ah, that's what I've been using direnv for and my end goal is "cd into directory and ghcide, stack ghci, stack build work transparently" and avoid "create a stack wrapper script for ghcide" or "customize emacs to call stack first". I think your solution using the nix integration might also accomplish all if not most of these though. |
@codygman To be honest, I'm not sure if there is a strong reason to prefer one way over the other. As you say, using Also, the upstream I haven't used ghcide, but I know getting tooling working is sometimes tough. Without having used ghcide, I'm not sure what the best approach is here. |
I've addressed the first bullet point from this issue in #702 There's a TODO in Getting Started tutorial to specify how to use stack repl with haskell.nix provided packages. |
@cdepillabout Does your I was hoping to use stack as a sort of light ui, use haskell.nix to translate the package.yaml to nix expressions, then when stack starts up it simply does nothing but start up a That way we benefit from cachix storing the system and haskell dependencies. Edit: guessing no unless stack output for nix integration is the exact same:
|
And since it just happened... to avoid stack errors building the haskell files like:
|
However, a downside is That leaves me in a state where most things are installed with nix, some installed with stack. While it's not the worst thing in the world, it's not ideal, and puts a big damper on the entire point imo. |
I'm running into a very interesting issue where it seems that any Haskell dependency with a native dependency like I'll work on making a reproduction in my linked repo and submit another issue if that's the case. Hopefully if this bug actually is present, it's not just failing silently somehow. |
Not really. When you use Stack's Nix integration, there is no (easy) way to get Haskell packages compiled by Nix. Stack really wants to compile all the Haskell packages from scratch. If you want to get all the Haskell dependencies compiled by Nix, I'd recommend just using a cabal-based workflow, since it is able to use a package database built by Nix. |
In regards to my issue above, I couldn't reproduce with the simple example sadly 😞 After this change:
This test passed:
|
This repo uses stack after downloading Haskell packages from nix and things appear to work flawlessly (in the very simple case at least). I tried migrating this approach to a larger repo for work though and there are some harder to debug issues I have to isolate, though it still works nearly all the time on NixOS, almost as often on Ubuntu+nixpkgs, and likely similar on MacOS+nixpkgs but target/lorri#362 is blocking testing there for me. It seems to be with packages that have native dependencies or silent errors about packages not in the dependency set. Not sure. For this approach to be truly robust though, there'd need to be a
I tried that, but my team wants to stay with That's what I'm working towards here anyway 😄 |
This is why I added the "(easy)" qualifier. While it is possible in some ways, it is not the easy path when using stack+nix. If you're going to venture off the easy path, you can expect to run into some problems.
I may have linked it to you recently, but Snoyman has been recommending people not go solely with |
Stack apparently has an Edit: opened an issue in stack at commercialhaskell/stack#5319 since this only applies to the |
@cdepillabout I just encountered one _potential_answer to "why disable stack's nix integration".
That will lead you to commercialhaskell/stack#5000 where @snoyberg says:
I've not been able to figure out how to fix this issue and I suspect it's something that pure nix/dumb stack solution would fix whereas the default smart stack/dumb nix solution falls down. |
@codygman Ah, that's an interesting catch. I've also run into this However, I don't quite understand why you're running into it here. It doesn't look to me like |
Yep, that's it. It calls stack or cabal internally. |
@codygman Hmm, if |
Note that commercialhaskell/stack#5000 was fixed in stack master. |
This is a WIP proposal of sorts, but is trying to record learnings from hacking around with haskell.nix's stack support during ZuriHac 2020. I think the ideal UX for a stack user starting to use haskell.nix would be.
Create a new stack project:
Add a default.nix:
Build it with haskell.nix:
That takes care of building your binaries, but then what about general development? Ideally I think you would do:
In practice though, this doesn't work out. I'm working on creating a repo with a readme that logs what happens when you try this.
The text was updated successfully, but these errors were encountered: