shajra / nix-example

a way to develop software with Nix
336 stars 25 forks source link

feedback #9

Closed aakropotkin closed 5 years ago

aakropotkin commented 6 years ago

This is an awesome guide. Nix is always in need of some extra documentation :)

Feedback:

For nix-shell you could have alternatively used "nix-shell -p hello" which is just a little less boiler-plate than doing an import expression on nixpkgs.

This is a little shell.nix that I use as a template for most projects. It's a little nicer than creating an overlay over all of nixpkgs, and should evaluate much faster. 'ghcWithPackages' also plays nicely with hoogle and similar tools. https://pastebin.com/JPqQuLRr

shajra commented 6 years ago

Hi @BadDecisionsAlex.

Thanks for the feedback!

I intentionally avoided nix-shell -p for a few reasons. I use nix run these days instead of nix-shell -p, which I like a touch more. There's an issue that discusses the reasons for my preference: NixOS/nix#726. Here's what my usage would look like:

nix run \
    nixpkgs.hello \
    '((import <nixpkgs> {}).haskellPackages.ghcWithPackages (ps: [ps.dhall]))'

I don't think this is too verbose, and I also think my tutorials cover enough information to explain how this works. Personally, I like some of the new Nix 2.0 commands. nix-shell is awkwardly overloaded with a lot of usages (debugging Nix expressions, developer environments, running commands). I do discuss nix-shell in the tutorials, but I was hesitant to discuss ways to use it that were redundant to other methods already shown. My goal was to make more singular recommendations congruent with my own usage, since in Nix it's easy to get decision fatigue.

Hopefully this all explains my thoughts. Right now my inclination is to leave things as they are, but I welcome more discussion. There might be a change to make still.

Thanks again for checking out the repository!

aakropotkin commented 5 years ago

Hey Sukant do you use hdevtools or a linter with Haskell and Vim? I have been having issues getting mine to play nicely with Nix. You know the issue already I bet; once I'm inside a Nix Shell, my linter is still referencing my global packages and whines about "missing modules" because it can't see the shell's Haskell Packs.

Cook says howdy and hopes you're well. He spent half of his previous lecture talking about eating edibles in Amsterdam and marijuana legalization instead of closure diagrams lol.

shajra commented 5 years ago

Hey @BadDecisionsAlex,

I realize now the connection between the account and the human. Good to know Cook is doing well and enjoying all of his favorite plants and related legislation.

Regarding you usage of nix-shell, you seem to understand the problem pretty well. You need to run these tools from within a nix-shell, I think. There's other ways to solve the problem too. What I do with Emacs is set it up with direnv-mode. With direnv, I can get my environment from nix-shell per buffer/file. Otherwise, you have to do aliasing/scripting/configuration/whatever to get all these tools to integrate with nix-shell. Another way to deal with the problem is to just go into the nix-shell, and then run your editor and tools from there. But that can be annoying when hopping from project to project.

I don't use hdevtools. There's so many of these things out there. The more stable ones I know of are ghcid (pretty plain, and not editor-integrated), intero (emacs-only, stack-only), and dante (emacs-only, stack-independent).

Additionally, there's this more complicated thing call the HIE server, which people normal figure out when using VSCode. From what I've seen, the HIE server doesn't seem too unstable but it's Stack-dependent. You can get the HIE server working with Emacs and Vim, I'm sure. But from what I can tell, HIE is a little bit more tricky to get working with Nix (versions of dependencies are different from what's in Nixpkgs).

That leaves ghc-mod and hdevtools, which I often hear about more from Vim users, which I haven't been for some time. Unfortunately, these tools also seem a bit more finicky.

So all I've gotten to work really well with Nix is the exact Emacs configuration I detail in this project. I hat that I'm so locked into Emacs. I love Emacs, but it pains me to not have more solutions for other people interested in Nix. Because I like Nix so much, I don't want to be tied to Stack, but unfortunately, that's what so many of these tools depend on. I have a lot of respect for the simplicity of ghcid, but Dante+Emacs gives me a tidier in-editor experience.

As for a linter, I do have Dante set up to give me not only compiler warnings, but also hlint warnings too.

All of this is documented in this repo under tools/README.org. But it pulls you into my exact toolchain, which I know is highly subjective.

shajra commented 5 years ago

Hey @BadDecisionsAlex, I'm going to close this issue. The conversation has been great, though. If there's something you'd still like to see implemented, please free to reopen the ticket. I'm happy to keep the conversation rolling. I'm just pruning my backlog.