DEV Community

Cover image for How to start using nix?
Lucas Quaresma
Lucas Quaresma

Posted on

How to start using nix?

If you're a Linux user, it's possible you could have heard some fuss about Nix.

But what is it? How to use it? Where could you start?

This post intends to present some introductory answers to ease the burden of your path coming into the best side of the force.

What is nix?

Nix is tree things, all at once, alt at the same time. They are:

  1. A programing language (therefore referred as nixlang).
  2. A package and dependency manager (that includes other nice tools).
  3. An operational system, in the form of Linux distribution, called NixOS.

The relationship among these parts, on a pretty high level, can be explained by:

  • 1 is used as a means to work with 2 and 3. For instance, performing shell commands on 2, and writing .nix config files on 3.
  • 2 is used in 3 as the manager for all packages and dependencies.

Declarative builds

The most interesting feature of all the nix ecosystem is being completely based on declarative builds and configurations.

We'll not go any further in details here, but think of packages that never change, builds that are completely stable, and reproducibility everywhere you go. No matter what happens, if your config worked once, it will always work.

Where to start?

After this brief introduction you might be wondering where to start. If you should try something like NixOS on a virtual machine, or fully dive into it and substitute the OS on your work machine. The answer is for sure: no.

I used Linux myself for about ten years, even though, when switched to NixOS with no experience on Nix (the package manager) or nixlang, it was a big headache. The logic of nix and declarative systems is not similar to other Linux distributions, so the most probable result of doing this is giving up on it. However, if you're really stubborn like me, and have a bit of brio, it's possible. Once again, I do not recommend it.

One other thing to avoid is all the experimental features, like flakes and nix develop, or non-declarative alternatives, like nix-env. Do not use experimental features!!! But if you really want to learn more, and in spite of my advice if you do use them, for the love of god don't complain about it for the community, were not responsible for you skill issues.

What you should start learning is the the basics, just the basics. First, take a look at the docs for the nixlang, it's not great, but they will give you an overall idea of how things work and some capabilities to work with .nix files when needed.

Second, you should be able to understand how to use nix-shell and it's features. In my opinion it's one of the simplest, yet most powerful things in the whole ecosystem. With it you can create purely declarative, completely isolated and ephemeral shells, that can be used anywhere, on any Linux distro, and give you real power. Along with it, it's possible to integrate them with bash, use them stand alone with simple terminal commands, or based on <shell_name>.nix config files.

Third, you should be able to understand and configure nix package channels, understand how generations and unstable branches work and how to mix and match them to your liking. I recommend star doing this inside nix-shell and any other nix environments. Use some packages from stable, others from unstable, look for things that are available in one of them and not the others etc.

Forth, go easy! What you should really be looking forward is to try nix on the small things. In that regard, it's much like bash, it will not solve most of your problems, but will for sure make your life hell of a lot easier. Look for small things like test environments, quick setups, the disposable spaces where you want to use some new thing and be sure it will not hurt your system configs etc.

When will you be ready to use NixOS?

This really depends. For me, changing distros was kind of a necessity since I was in distro hopping hell due to Nvidia/TensorFlow fucking ecosystem for CUDA and machine learning. It saved me and thank god I have no longer this kind of problem.

However, sometimes on NixOS you could have other problems. You are not me, and your problems and tradeoffs can be different than mine. If you already know the basics, and think the tradeoffs could be worth, go for it.

One thing I can say for certain is, if you have a single stable system, you'll always have at least that version working everywhere. That is more peace of mind that you could ever find elsewhere.

Concluding remarks

For me, using the whole nix ecosystem has been a wonderful experience. It solved so many problems I had and didn't think there could be a solution. It also helped me to make elaborate things work in the most simple and elegant way. If this kind of thing is what you're looking for, nix could be for you.

Lastly, good luck! I hope this post can give at least some idea or inspiration on where to start.

Top comments (0)