DEV Community

Bruno Noriller
Bruno Noriller

Posted on • Originally published at Medium

Nix at level 0 is still awesome

There’s a recurring joke that once you understand monads you lose the ability to explain monads. Well… I think this weirdly applies to Nix.

What is Nix

There’s nix: the language, nix: the package manager (think apt, dnf…) and related NixOS, the OS based on nix (both language and package manager).

I won’t go further than that and it’s not necessary for now except to say that it is the one package manager with the most packages available.

Which Nix are we talking about here?

The package manager.

Why use Nix?

Recently I was playing with IP ranges, so you could use a package like ipcalc but you have to install it and then it will stay there… even if you do remove it, maybe something will be left behind.

And let’s not think about conflicts on dependences…

Nix solves both problems, but for that, you need to install it.

Installing Nix

While you can use the official installer: https://nixos.org/download/

But the one I recommend and I’m using is: https://github.com/DeterminateSystems/nix-installer

Which handles a lot of problems, including some quicks of some distros (including even MacOS and distros under Windows WSL).

Using Nix:

Before using it, I do need to expand on what you know about Nix here.

All packages are packages that have their own list of dependencies, which also might have their own list.

If you know JS and the package.json, it’s like that.

one-of use

Do you need something only occasionally? Maybe you want to test something or evaluate which option is better?

nix-shell -p plus the name of the package(s)

(which, by the way, you can find here: https://search.nixos.org/packages).

That’s it. All you need to know is that it will create a shell with the packages available, and if it has conflicting dependencies? It will just use the ones it needs and ignore the rest.

Once you exit the shell, it’s all gone (* terms and conditions apply).

actually “install”

nix profile install nixpkgs# package name and if needed, nixpkgs#other-package all in one line.

Now it’s installed and ready to use.

removing things

If you “installed”, then remove with nix profile remove package name, and that's it.

Then for those you’ve removed and those you’ve played around with nix-shell

nix-store --gc and it will be actually, all gone with disk space freed.

You see… Nix downloads packages and dependencies and uses them from a store. The first time you need something it will take time to download everything (and by everything, I mean everything… even “low-level” utilities you take for granted… all to keep everything pure and working). Again, like in the JS ecosystem.

Outro

I can’t see myself without Nix anymore… it’s just so handy to pull packages as you need them without worrying about having to remove them later or weird problems happening because you, at some point, had installed something that needed some version of some dependency and it never got updated.

If you start checking out nix (language), nix (package manager) and NixOS, then you’ll probably be overwhelmed by the sheer amount of information, but believe me that these 2 (3 if you consider the one to clear unused dependencies) is all you need to solve most of the problems you might have and even just manage your dependencies overall.

And if something didn’t work OOTB? Just install it the way you would normally.

I hope I can manage to keep learning while retaining the ability to explain it… so that I’m confident in what “level 1” would be… then expect more to come.

Top comments (0)