Development environement habbits from previous distros

I’m quite new to NixOS, and I’d like some insights on what are the good practices for a developer that switches all day long between versions of language/framework.

Usually, on my previous ArchLinux setup, I would install rbenv/pyenv/nvm and I would simply switch between my folders and let the scripts do their jobs when I enter the folder.

I have the feeling that this would not be a natural approach for NixOS, and I was wondering what would be the Nix-way of having such a devenv ?



It kinda depends, I moved from Arch too and in the beginning I just installed all the required things with nix-env and used them as normal, as time progressed I’ve moved to having all the packages and such in home-manager and more recently I’ve actually started using Nix to setup development environments for various programming projects, some samples (note that I use niv to manage the nixpkg version):

  • Skall: a Rust project where I pin Rust to the latest available stable from the Mozilla overlay. I also use gcc9Stdenv so I can use lld as my linker.
  • course-explorer: a Python project (with some Node stuff that I’ve ignored for now) where I include all required pythonPackages in the derivation so I don’t have to use pip/poetry/pipenv to manage them.

Together with direnv the workflow is really smooth; I simply cd into a directory and it automatically setups a nix-shell for me with the dependencies in my shell.nix/default.nix. This is really my first foray into actually using Nix for managing packages, I’m looking at using it while learning more Haskell because I know lots of people love the Nix/Haskell combo.


Thank you for your reply, it made me discover home-manager and direnv.

direnv with the combination of a default.nix file seems to be the perfect fit !

I’m currently working on setting things up.

I will make a feedback on how it went once I finished to put all the pieces together (in my case, mostly with multiple Ruby on Rails projects with multiple Ruby/RoR versions and dotnet-core projects).

1 Like

Everything is working as excepted. direnv is working really well, and with the use_nix directive in direnvrc is making it really easy to activate a custom env. I have even been able to group the default.nix files since I have the same versions and requirement shared between multiple projects.

I still have 2 points that I would like to clarify :

  • Everytime I enter a folder with a default.nix file I have a warning message saying : warning: ignoring the user-specified setting 'show-trace', because it is a restricted setting and you are not a trusted user. I have the feeling that it is related to this issue but I didn’t figured out how to suppress that warning.
  • If I require a version of ruby that is not in the repositories, how should I proceed ? Usually, I use rbenv install that adds the ruby version in my global context (which sounds quite a bad thing on NixOS), is there any equivalent ? Like building my own derivations ?

Thank you for your help !

You might also be interested in lorri.

  1. Yeah, not sure what gives about the show-trace line, I just ignore it. I asked about it somewhere and it is harmless, but slightly annoying.
  2. Not sure honestly, I have never been in a situation where the latest version didn’t work so I just use whatever is available. I see that there are a couple of versions available for Ruby (Ruby 2.4, 2.5 and 2.6), would that be good enough?
  1. I confirm that the merge-request previously linked fixed the issue : I switched to the unstable branch of nix and it made the warning disappear.

  2. No problem, I will figure it out and I’ll post on this topic later with a solution.
    I do not see the ruby_2_6, but only ruby_2_5 and ruby_2_4 package on the 19.09 stable and unstable branch, I am using this link on to search for packages, is their a better place otherwise ?

I mostly just do nix search <package> to look for it, when I do nix search ruby on 19.09 stable I see

* nixpkgs.ruby_2_4 (ruby)
  The Ruby language

* nixpkgs.ruby_2_5 (ruby)
  The Ruby language

* nixpkgs.ruby_2_6 (ruby)
  The Ruby language

And a quick nix run nixpkgs.ruby -c ruby --version show that the regular Ruby version is ruby 2.6.5p114. I see that neither rbenv or rvm is in nixpkgs, might be something to contribute in the long run :slight_smile:

1 Like

What do you need it for? You have nix-shell, which can do pretty much the same.

@sondr3 : Thanks, I found the package using the nix search command. It’s strange that the index on the website is not updated ? Isn’t Hydra supposedly updating the website’s packages/options indexes ?

@NobbZ : I understand why you say this. What do you think of this approach : let’s say rbenv adds a backend that generates a nix environment automatically using information from the Gemfile.
It could help developers that are switching to NixOS. I will do some digging and maybe send a PR on rbenv and/or nixpkgs if I end up with something usefull. :slight_smile:

1 Like

I agree, but I still primarily use rustup for managing Rust instead of setting it in my shell.nix file per project. It’s just a nice convenience, especially when you want versions of Ruby that aren’t in nixpkgs, then you have to resort to making your own overlay or package.

1 Like

@Elyhaka I’m interested in how you ended up working with projects which need different patch versions of Ruby. This is very straightforward with rbenv, but it’s not obvious to me how to do this with nix which seems to want you to always use the latest patch version of a specific Ruby minor version. I’ve read that it is possible to use nix with an older version of nixpkgs to find the relevant patch version of Ruby, but that seems like a lot of hoops to jump through. Do you have any insights?

Hello, I believe using pinned version of nixpkgs might be the easiest way.

I’m not using specific patch versions of Ruby, only specific minor version (since it does not break), not sure how to get specific patch releases.

1 Like