Why would I need to reinstall my OS?

As a Windows user I’m looking for a Linux distro to start using as my daily driver for my devops hobby’s. I’m a reasonably experienced Linux user. I’ve been maintaining all kinds of linux servers for the last 10 years. I’ve had personal Linux based servers at home for just as many years, for many different purposes. I’m ready to make a transition from Windows to a unix based OS.

Everybody, no matter where I look, is overwhelming enthusiastic about NixOS. And the idea of an easily reproducible OS does sound amazing. However I’m going play devil’s advocate here because I do have a question I couldn’t find an honest answer to.

Why would I need to reinstall my OS?

I’ve been using Windows on my laptop since I bought it in 2019, and it’s still running stable and smooth. The only times I would need to reinstall my Windows OS is when something bad happens to my laptop, or I buy a new one. Both are very unlikely to happen for the next few years. But yes, then I would need to setup my environment from scratch again and restore my backups.

From the outside, at least to me, it looks like NixOS is solving a problem that doesn’t exist. It probably feels amazing to reload your OS from your config file and start fresh, but do you actually need to once it is setup the way you like it?

A big disclaimer in case it isn’t clear yet: I know almost nothing about NixOS. However before spending hours and hours on NixOS in the little spare time I have, I would like to understand someone’s honest perspective on this.

This strikes me as a bit like playing devil’s advocate about why you need backups for a relatively new system that’s been smooth and stable since you bought it. The reasons are the same.

3 Likes

It’s uncommon, but my system config tends to be complicated enough that it is impossible to replicate. Even when not, I tend to over time apply little hacks and things that I would have no idea about anymore 10 years in the future, with NixOS I have everything maintained with git commit history and comments available.

Just check out my nvidia config, do you think I’d remember to re-enable the PAT option if my SSD dies or I buy a new motherboard or such? https://github.com/TLATER/dotfiles/blob/31330ef571862f764c3e18936e0c3761f603c9a7/nixos-config/yui/nvidia.nix#L20

It’s certainly not necessary, but my system setup time for a new device has gone down from months/years to minutes. Sure, this is effectively no real time saving since it’s a rare event, but the knowledge base I’m building will persist the ages.

Also home-manager is amazing, I have (had?) to use various customer-owned hardware on a regular basis, being able to just instantly have emacs running with all my packages and the various CLI tools I need is very useful.

5 Likes

I think “not needing to reinstall the OS” is only one of the benefits of NixOS. In fact, it’s probably a rather minor one that’s partially incidental to the guarantees of the system.

I would consider some additional benefits:

  • No program or library remains installed in your system (at least in its current environment) that isn’t specified by your config or its dependencies. That means you never have to worry about cleaning up junk in your system that you forgot you installed, or whether that junk is needed by some critical service.
  • Since your entire configuration is in a text file, it can be tracked in version control. Indeed, multiple machines can track the same git repository (especially if using flakes) to share common parts of their configuration consistently.
  • Much of the root filesystem is immutable, which prevents making certain kinds of system-breaking mistakes and provides some security benefit.
  • Updates to the system must be successfully built before they are applied, which improves the likelihood of success.
  • Even if a “bad” update is applied, you can always revert to an earlier generation of the system at boot to restore a working environment.
  • You can install multiple conflicting versions of the same package on your system at the same time. You can also pin packages to specific versions or compile them based on specific source code commits. Package attributes are easily modified and source code can be patched as if it were the original being served by the repository.
  • Nix separates “building” a package from “activating” it in your current environment. So just because a program is installed to the Nix store doesn’t mean it’s installed as an active program. This means you can run a program once to try it out, and then afterwards it’s as if it never existed. It will simply sit hidden in the Nix store until you need it again or it’s garbage collected.
  • Edit: I should also add that setting up some services is actually easier in NixOS. For example, you can setup Jellyfin in a single line (services.jellyfin.enable = true).
7 Likes

There’s a caveat to this that, by default, NixOS can’t do anything about data left over by those programs, say in /var/lib or in various hidden directories in $HOME.

Of course, this can be rectified using this method unique to NixOS: https://grahamc.com/blog/erase-your-darlings/

1 Like
  • when you have multiple computers you want to behave exactly the same way
  • when you replace your computer when it dies
  • when your storage dies
  • when you make a huge mistake destroying your system
  • when you moved out of NixOS because whatnot and you know you can quickly install it from scratch without any pain if you kept the configuration file
5 Likes

Welcome delta1! Your question is a fair one. I think others have done a good job of identifying the advantages of NixOS, so I’m going to focus on expanding a few points.

I’ll start by saying that I personally wouldn’t recommend NixOS as a first distro to install, even for someone who is experienced at using Linux. The learning curve is steep, and won’t seem worthwhile unless and until you have a strong motivation for learning it. (However, I do recommend trying the Nix package manager to anyone, as an alternative to build systems like Maven, or as a way to set up repeatable project-specific build environments.)

Throughout my career, the companies I worked with would supply me with a laptop or desktop. Every two years or so I would get a brand new machine. I’d install the software I knew I needed, and start using it. The first week or so would be pretty frustrating, because I’d start to work on something, only to realise that I needed some software I’d forgotten about, or I was missing some of my custom configurations from my old machine. I’ve been developing software since 1979, so I have a lot of customisations and little tools that I rely on; trying to work without them is truly painful.

With NixOS, I can have a brand new computer up and running in about 20 minutes that is identical to my previous computer, with all my software and customisations. I can have identical environments on my work machine and my personal machine. This is my number one reason for using it.

Last month I was trying to debug a weird hardware problem that might have been the motherboard, the hard drive, or even the power supply. I’ll spare you the gory details, but I ended swapping parts and rebuilding the machine at least a dozen times over a period of three days while trying to solve the problem. I really appreciated NixOS then! Granted, that’s not something the casual computer user would do very often.

I also love the fact that even major distro upgrades are painless and safe. If something does go wrong, I can boot into the previous version.

From your post, it doesn’t sound like you’ve had the sort of problems that would make NixOS worth the learning curve. However… it’s very intriguing that you found your way here! Most people who are looking to set up their first Linux machine wouldn’t have done the kind of research that would make them aware of NixOS. I have a feeling that you like to learn and challenge yourself. Whether it’s now or later, I bet you’ll be trying out NixOS, and you’ll be very welcome here.

7 Likes

Thanks for your wonderful and insightful response. And thanks for all the responses.

I can definitely see where you (all) are coming from. There are many situations where NixOS’s unique quality to easily start fresh or revert to an earlier generation are extremely useful. But indeed, all in all I’m not sure if in my case NixOS is the right starting distro.

But darn it, NixOS has been on my mind constantly since I heard about it last week. I usually don’t shy away from a challenge, so I couldn’t hold myself. I created a new partition and now I can dual-boot into NixOS. I’m pretty sure i’m in over my head, but at least I want to really understand why it’s maybe too early. We’ll see.

8 Likes

If you’ve gotten that far without help I wouldn’t worry too much.

You’ll run into a variety of sharp edges here and there, but if you’re familiar with using Linux in general and have thick skin when it comes to having to debug things that you normally expect to just work™ I don’t think NixOS is actually hard. The documentation and UX aren’t perfect, but there is an actual functional distro that is very usable behind the initial stumbling stones.

If you run into problems, ask and search on this discourse, someone can usually help, and it doesn’t sound like you’re doing anything exotic.

Just be patient and actually give the distro a chance, it’s great once you’re comfortable with it :slight_smile:

This is my shortlist for beginner traps:

  • Be careful with user vs system channels. They’re completely independent, so if you install the same software from both you can end up with one hiding the other, and ultimately you’ll run into unexpected version mismatches.
  • This is especially true when combined with the hot mess that is nix-env. Sadly it’s how most people first use the distro, because it feels more like the familiar apt and therefore is kind of the path of least resistence…
  • Anything that doesn’t come directly from the nix package manager is difficult to get to run, because of how NixOS works (there is no /lib, so everything from the linker to libc does not exist). You can try steam-run for binaries, but if you’re used to installing things with npm, pip, etc. you will need to find a new strategy for doing that.

Those three together IME piss off some new users enough that they storm off calling us insane.

2 Likes

I made a video introducing NixOS to new people, maybe this could be helpful for you

6 Likes

Promising words and great advice. Even though I’m only scrating the surface, I feel like I’m already getting the hang of it. You guys make me feel very welcome as a total newbie.

Very nice to see the video introduction @Solene. I’m going through it right now. :slight_smile:

1 Like

I’m not sure what kind of things you like to do with your computers, but a reasonable middle ground is to use nix not to configure your whole system (NixOS) but instead to declare your project dependencies.

Suppose you land on a debian-based distro, then you’d be using apt to install things. You can install nix alongside apt and also use it to install things. On the surface that sounds like maybe a bad idea, who wants to have two competing package managers?

The thing is, if you have projects that ask the user to invoke apt, you’re leaving the people on non-debian-based distro’s in a situation where they have to figure out the equivalent packages if they want to use your projects. You’re also asking users to make global changes to their system just to tinker with your project, which might seem normal to an outsider, but we here in NixOS-land find that to be a little bit rude.

So that’s where nix would come in. Avoid commands like nix-env which will alter your global environment–use apt for that so you have a single source of truth for what’s installed–and stick with nix develop and nix build and nix-shell for project-level work. These will not make system-wide changes, but instead will give you access to an environment with nix-level determinism–the definition of which lives with the project that it’s designed for.

Want a different environment? Exit that project’s shell and activate a different one (direnv is nice for this, you just cd to a differnt project and it activates the shell for you). ow you’ve got a totally different set of things installed–and they’re the right things for that project. Users can still use apt or whatever to install dependencies if they want to, but now they’ve also got the “let nix handle it for me” option.

Then later, if you become convinced that that level of control is kind of nice and you want it everywhere, not just for individual projects… then is the time to switch to NixOS.

Also, it doesn’t have to be code that you’re working on. I have this project in my back yard where I’m taking pictures of flagstone (I’m going to print them out as puzzle pieces and figure out how to fit them together as a patio… solving the hard problem with small pieces of paper instead of heavy stone). I use nix-shell -p geeqie gnome.cheese gimp to give me an environment with a picture-taker and an image viewer and an image editor and then I get to work. When I exit the shell, the tools are “gone”. I just like the feel of a blank slate.

Maybe that’s a bit extreme, maintaining a totally empty system like that, but I like it. Something something… non-attachment.

1 Like

Haven’t touched Windows in any serious way in almost a decade, but fwiw as a user of it for about 15 years before that, I remember reinstalling my OS far more often than “never” to fix the mysterious and perpetual bloat that seemed to occur on a Windows macine, at least back then :person_shrugging:

That said, I am not sure the one and only point of NixOS is to never have to reinstall your OS again, even if that pops out as a useful side effect. The higher level goal, in my view, is to give you a sanely reproducible system in a guaranteed manner that is only possible using formal methodologies. In other words, if you get it working, it stays working, and that’s that (guaranteed using formal mathematical tools, instead of merely clever engineering).

And if and when you do break something on updates, there are highly useful tools for quick and painless rollbacks to a previous state. I remember years ago using a tool on Windows that essentially put most of the system in a read-only state so that perpetual bloat was less of an issue, but it was a bolt on, paid or piece of software, and if you actually wanted to make an underlying change to the system you had to reboot to “unfreeze” the OS layer, make your change, then reboot again to “refreeze”. In a way, NixOS is kinda like that, but more streamlined.

In general, there are more benefits to having a reproducible development machine than merely not having to fiddle with OS reinstalls from time to time. Especially for someone like me, who doesn’t simply use the latest spin of Gnome or KDE, but has highly customized configs for everything I use, it is extremely useful to be able to reproduce my working setup across machines and environments, with almost no effort.

But to actually answer your question, on other distros, at least, I’ve had many, many, many exeriences where a system update left my system in a broken state such that it was more straight forward to simply just reinstall from scratch. Granted I am a bit of a tinkerer, so perhaps that is only due to my temperment, but I can only speak from personal experience.

To really sum it all up, I feel after using NixOS for quite a number of years now, that I have been able to focus a great deal more time on actually solving new and interesting problems, and less on annoying and tedious issues caused by random updates. Not that that doesn’t happen when using Nix, but unless you are 100% blocked and in need of your new update for some specific reason, you can just rollback and continue useful work until you have more time to figure it out later.

1 Like

@Solene answered almost exactly what I was thinking initially.

To me, the main selling point of NixOS is to build the whole OS from a GIT repo (or any repo for that matter). No one knows when your spinning hard drive becomes unusable.

1 Like

Aside from all the good points raised, there is also documentation and conditional configuration.

  1. documentation

Let’s say your NIC doesn’t come back properly after the machine was suspended so you need to disable power management on it. On Windows you would fiddle around with the driver settings which ends up writing a value to the registry. If the device is domain joined you might do this via group policy, but it’s a lot of hassle for one setting. Some places might document this in a knowledge base type system.

With NixOS, your configuration is just a text file, so you can put in comments concerning why this setting was made, what else was tried, links to upstream issues, etc. Everything is kept together.

  1. conditional configuration

Following up on the earlier issue, let’s say this particular problem was then solved in kernel version X.Y+2, but you’re currently on X.Y. You now have a few options (and let’s ignore the “ignore the problem option”):

  1. apply a workaround such as disabling power management, but only if the current kernel is < X.Y, or
  2. pull down the patch that fixes the problem and recompile the kernel, but only if the current kernel is < X.Y
  3. do nothing because we are now running X.Y

The problem is solved, documented and best of all - when you eventually have a kernel version with the fix, all your workarounds/custom patching no longer happens and things just work.

2 Likes