I daily drive NixOS and usually spend time on my computer in a web-browser or in Emacs1. It's fun and all, but one particular feature of this combination has so wildly increased my productivity and comfort that I can't believe I used to do things in a different way: Nix flakes + direnv
+ emacs-direnv
.
I'm gonna try to sell you on this even though that does nothing for me. This is more of an excuse for me to show off my setup.
What are we trying to achieve?
We want the ability to jump into any project2 having absolute confidence that:
- We have all our tools needed to work on our project ready
- The tools integrate neatly with our Emacs config (LSP and all)
- We needn't remember what we did to facilitate this
How do we achieve that?
Well we define the tools needed to work on the project in a flake. We do this per-project, all the time. To make this process less tedious, especially if we're using the same toolset for different projects, we may define some nix flake templates.
Then, once we have our tools defined, we use direnv
and its use flake
directive to enable our devShell
when we jump into that directory.
Finally, since we don't want to M-x ansi-term
to use the tools and since we want to integrate the appropriate LSP and use good old M-x project-compile
for our projects, we integrate direnv
with Emacs using the package emacs-direnv.
Thus, we have a neat little modus operandi for working on our projects.