Hi, I’m a data engineer who has recently gone all in on nix to manage my various machine configurations. Since I primarily use macbooks, I’m focused on nix-darwin and home manager at the moment. I’ve converted my git repo where I used to store all my scripts, configs, dotfiles and other minutia into a nix flake and I’ve gotten it mostly working pretty well for setting up my environment.
But here’s where I’m struggling. I frequently have to deal with different versions of java, scala and python. I’ve used jenv, coursier, and venv in the canonical ways to install and switch between these versions in my various project roots. But now I understand those tools don’t play nicely with the nix ecosystem, so what is the best practice nix way to manage this? I like to configure my Intellij Idea to use the same tools that I use at the CLI but I am CONSTANTLY having to reconfigure Intellij every time the nix store changes. Does anyone know any tricks?
I’ve started reading Development environment with nix-shell - NixOS Wiki and, one approach I’m looking at involves not installing ANY dev tools for my base environment and then creating dev shells for each of my project repos that contain the specific versions I need, a la direnv and friends. But, for some reason, these shells take dozens of seconds to start (annoying) and sometimes get hung up. Furthermore, if I’m working in a git repo, then nix complains that the flake.nix I’m using isn’t checked into git and gitignoring doesn’t seem to help. Some clients don’t use nix and don’t want it in the repo so checking in is not an option.
I guess I’m just looking for some general advice from other developers on how to make this as easy as it seems it should be…
https://wiki.nixos.org/wiki/Flakes#How_to_add_a_file_locally_in_git_but_not_include_it_in_commits mentions a workaround. And do use wiki.nixos.org, the other wiki is dead.
You can also locate the flake.nix
elsewhere, but keep the .envrc
in-repo and gitignored, and ensure the .envrc
points at your flake’s location.
Shouldn’t happen unless you bumped the flake input, so bump less often perhaps.
why?
I’m not convinced it can as easy as it seems it should be, but I’ll be following other replies in the hope that I’m wrong.
The trick I use for java + intellij is to launch intellij from the shell, in which I make sure JAVA_HOME is set. It’s annoying if you want to have multiple projects open with a different java.
I did not find an equivalent for python / pycharm. No idea about scala.
A shell taking repeatedly dozens of seconds to start is surprising, maybe start the shell with -v or -vvvvvv to see if it hangs on something like a proxy or a specific evaluation.
I did have annoying long startup time when I tried to use flake on a project with a very large git history. I ended up ditching (and disliking) flakes.
https://wiki.nixos.org/wiki/Flakes#How_to_add_a_file_locally_in_git_but_not_include_it_in_commits mentions a workaround. And do use wiki.nixos.org, the other wiki is dead.
Wow! Cool trick!
You can also locate the flake.nix
elsewhere, but keep the .envrc
in-repo and gitignored, and ensure the .envrc
points at your flake’s location.
Yeah this is what I’ve been doing, but I like the above trick much better! Thanks for that!
I am CONSTANTLY having to reconfigure Intellij every time the nix store changes.
No idea (bad pun intended). It just seems to keep “forgetting” which jdk or which scala I’m using and makes me reconfigure it. More annoying than anything else, but it makes me think I’m not doing some right…
I’m mostly using devenv to define the environment for individual projects. It is fast to load an environment you’ve loaded once before.
It integrates with direnv to load environments when you enter the project directory using your shell.
It supports many different languages/tools, with support for their special quirks (venv, JAVA_HOME, etc).
It has support for multiple versions of tools for some languages using community maintained flakes, like for python.
It uses the same module system as NixOS with loads of options.
1 Like
Ooooh, that sounds nice! I will look into that one. Thanks for the rec…