Should I try NixOS?

I’ve seen a few people mention NixOS.

I never heard of it before a month or two ago. I pretty much only use Ubuntu 16.04 and 18.04 systems these days. (not counting my Mac, which I use most of the time)

What do the adherents of NixOS like about it?

I will speak from the perspective of a casual desktop user. So first of all if you decide to try NixOS be sure to have several spare hours or better days for this. You are going to learn a new philosophy and the basics of a whole new programming language. The distinctive feature of NixOS is its declarative package manager. To install a package - and indeed the operating system itself - you’ll first need to write or get a recipe for it. Then call the interpreter to process the recipe. Somewhat similar to make or brew files but distinct in the underlying programming language and arguably more suitable just for this purpose. There are of course tons of such recipes in the Nix repository, which should make the beginner’s life easier, but still…

So what people like about NixOS is that the declarative package management allows for 100% reproducibility of a system state. With the same recipe you will always get exactly the same system. For example, when using an ordinary package manager, it may happen that some packages get upgraded, some do not. If package A of version 1.1 requires package B minimum version 1.2, you may actually end up in one of several possible states, where after upgrading package A v1.0 to v1.1 you’ll have package A v1.1 + package B v1.2 or package A v1.1 + package B v1.2.1 - depending on what’s available in the repository. An ordinary package manager will get just try to get the most recent version that is available. With Nix, you will specify package A v1.1 + package B v1.2 in the recipe and that’s what you will always get. You can also have several (dozens, thousands) different system states installed simultaneously and they will not interfere with each other. Moreover, you’ll be able to straightforwardly switch between such states. This isn’t something that can be easily achieved with an ordinary package manager.

You may now see where and for whom this is really useful - automatic deployment, software development and continuous integration testing.

If you are still interested, I’d recommend you try Nix package manager first. It’s available for all Linux distributions and also for MacOS. So what’s good about Nix package manager is that you can have exactly the same set of packages on MacOS and Arch Linux. Think of NixOS as a superset of all imaginable Linux and many Unix-available packages and system states, in which Ubuntu 16.04 is not a distinct Linux distribution but just one of the many possible NixOS states. Theoretically, it’s possible to have Debian and Fedora (which are just fancy names for a specific set of specific packages) installed within the same system.

I personally do not use NixOS nor Nix package manager myself.

3 Likes

Just to give an example from the Emacs world, Nix package manager is to Apt (or RPM or Pacman) what straight.el is to package.el.

1 Like

I’ll try to add my 2 cents

I could recommend to read a little bit about Nix, to check whether it’s selling points click with you.
Then trying out Nix package manager on you current distribution and after that - maybe installing NixOS on a virtual machine.
I installed it as main OS during winter holidays, but already had some experience with nix and set aside several days to read documentation
(Yet I’m still far from proficiency)

The Good:

  1. declarative configuration means many things
    • after modifying system configuration or upgrading packages you can ‘rollback’ to previous configuration
      and will be exact previous configuration.
      With Nix package manager this works for packages, with NixOS - for any OS modification, you will just have separate historical GRUB record that would boot previous system, regardless of changes you did - change in drivers, kernel, applications
    • I have two notebooks and lot’s of configuration is common between them:
      so if I modify one system & commit changes to git - on another machine I could pull changes, do ‘nixos-rebuild switch & home-manager switch’ and my other machine would also match new configuration
      There are examples of people managing their VPS machines this way and that is quite nice in comparison to having machine with very state that was achieved by lots of manual changes
    • From my nix config I could set up new machine with exact configuration - WM, apps & their configs much faster than if I had to do that by hand
      it’s like applying my emacs config but on the level of whole machine
    • packages depend on different dependencies and those don’t interfere with each other
    • So there is much less fear in modifying the system, there’s youtube talk about “fearless tinkering on NixOS”
  2. NixOS basic installation is well documented, and lot’s of things work well out of the box
  3. You can use Nix as package manager on any linux distribution, so no need to dive deep from the start
  4. Nix is a technology for writing packages, that could be installed in declarative manner with Nix package manager
    it can also be helpful in creating recreatable develpment environments, if you do programming
    so that you enter into ‘nix-shell’ with specified environment: packages, dependencies - and have access to them without installing all of that system-wide. And your colleagues or your other machines would share exact same configuration for specified project

The Complicated:

  1. Nix language that is used to write packages is a specific pure functional language,
    considerable time is needed to get to proficiency
    So if you’d need something less default - that would pose different levels of challenges
  2. nixpks - is a repository of different packages that can be installed, they are written in nix language, and there are different function libraries & coding styles that also need to be understood to use in advanced cases
  3. Solving unusual problems might trip you up a lot.
    One of the common problems I heard about - the desired package is missing from main repository
    If it can be found in ‘unstable’ or ‘nix user repository’ - the problem is simpler, if it isn’t - harder

P.S there is also ‘guix’ project - it is also a declarative package management, with lisp dialect as language for describing packages.
It also used to create whole linux distribution in declarative manner.
I’m not sure how these two projects compare to each other, only know that Nix has extremely active community creating packages and supporting ‘discourse’ communication.
If you are a lisper, you might want to check it out too, that could shave part of the learning curve

2 Likes

The basic value proposition of Nix is that you don’t install stuff; you just say what you want installed. Nix looks up how to install that thing from the “Nix repositories”. So if your system breaks, or you upgrade your OS (even NixOS has different versions, two new ones each year), or you want to duplicate your system on another machine, you just copy your Nix config files and say go, and it goes.

That all presupposes that the things you want are already in the repos. In my case almost all of them are, but I did have to write a couple “recipes” myself, and it was hell.

NixOS is not as production-ready as, say, Ubuntu. It’s not for the faint of heart. But you can verify before trying it that everything you need is already packaged, by visiting search.nixos.org. If everything is, you’ll have a relatively easy time. And all your learning costs are frontloaded. In fact they’re so frontloaded that I’ve actually forgotten how to do most of the Nix work I’ve done; my system just works, and all I ever do to modify it is add to the lists of things I want installed. Even Emacs extensions are packaged for NixOS.

1 Like

I think this is pretty much in agreement with everybody else, but my summary would be:

  • NixOS-style administration is the future of managing your OS (definitely for servers; possibly for desktops)
  • at the present moment, you’d have to be pretty dedicated for it to make sense for you (getting better every month!)
  • so I’d recommend it if either (a) you like the philosophy a lot, or (b) you’re okay with your OS being kind-of a hobby

I think the NixOS discourse is generally quite helpful.

And a random example of what’s neat about NixOS: one thing that’s possible (I’m doing this on my desktop) is erasing your root partition on every boot. The other thing that I really like is being able to install per-project dependencies (you’ll want to Google shell.nix). For example:

[zjn@zjn-home:~]$ pdflatex --version
The program ‘pdflatex’ is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix-env -iA nixos.texlive.combined.scheme-basic
  nix-env -iA nixos.texlive.combined.scheme-minimal
  nix-env -iA nixos.texlive.combined.scheme-small

[zjn@zjn-home:~]$ cd ~/git/authdict-paper/
direnv: loading ~/git/authdict-paper/.envrc
[...]

[zjn@zjn-home:~/git/authdict-paper]$ pdflatex --version
pdfTeX 3.14159265-2.6-1.40.20 (TeX Live 2019/NixOS.org)
[...]

I work on lots of projects with lots of different groups (which each have their own preference for language, tools, etc.) and this is a lifesaver. I can start with a brand new installation and be productive within a couple of minutes (no installing compilers etc.)

2 Likes

So is it basically Python’s venv but for the whole OS?

Exactly! It’s life-changing :slight_smile:

The way it works is kinda funny: rather than having packages stick binaries in /usr/bin and friends, each package gets its own immutable directory (/nix/$SHA256-package-name/) and then Nix magically symlinks things and changes environment variables (like $PATH) so that everybody’s fooled into thinking things are normal. (There’s a huge additional pile of hacks I’m sweeping under the rug here.)

This completely gets rid of issues like “binary B1 depends on library X version 6 but binary B2 depends on library X version 7” – you just have them living in separate universes.

One thing I’m not sure has been mentioned: you can install Nix (the package manager) independent of NixOS and get some of the same benefits (but it’s a little less supported). Might be a good way to test-drive.

1 Like

I use Org Roam on NixOS, and Nix lets me version-pin and build Org Roam as well as Org Roam Server. I recommend it.

1 Like

I absolutely love Nix, Nixpkgs, NixOS and home-manager. For some stupid reason I need to use Fedora as my main OS, but I have home-manager taking care of all of my user configuration (i.e., the dot files), the packages I need and systemd user services. This is just awesome.

I can’t wait to switch back to NixOS to enjoy the full experience.