From NixOS with Love
Tags: linux, tooling, beginners, productivity
Published: 2024-03-23 19:43:06



![Originally published on Medium](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fnhi6rhqhk8j7bq7bsg9.png)

For those of you who’ve read my previous article on immutability, you’d know that I’ve been somewhat starting to spread the word about (increasingly popular) **immutable operating systems**. While the concept and existence of these systems is nothing new, there have been several candidates with their own unique spin on the concept that has been truly remarkable!

**Many of the more popular and recognizable immutable operating systems include:**

- Fedora Silverblue
- macOS (surprised??)
- Vanilla OS
- NixOS

It is the latter of these that I’ve found myself enamored with over the past year, and it’s been one heck of a ride! I figured it was high-time that I shared this truly awesome experience, and help other `*nix` enthusiasts understand the profound impacts such an OS could have on them as well!
<br>
## Quick Recap
If you haven’t read my previous article on immutable systems, here’s a quick rundown of what we’re talking about here:

> Immutable operating systems are built with the principle of immutability in mind. This basically means that the operating system is designed to be unchangeable and unmodifiable during runtime. Any updates or modifications to the system result in the creation of a new instance or snapshot…thus making it extremely easy to rollback to a previous configuration should a change produce undesirable effects.

<br>
**This means that:**
- Instead of overwriting previous applications and files with their newest selves, an entirely new system state is created and stored separate from the previous one
- This new state is then available at system boot, alongside any previous states from prior upgrades
<br>
<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtxc6ct7lzfyijquqozu.png" alt="Originally published on Medium"/>

<br>
## Questions?
Many of you probably have many of the same thoughts, questions, and reservations that I did when considering testing out a system like NixOS. The very first thing that I thought of was:

> If each system upgrade produces a new copy of the system to boot from, won’t that use up a crap ton of storage space??

The short answer to this is yes, it has the potential to use up large blocks of storage space on your hard drive…but like I said...**that’s only the short answer!**
<br>
A more accurate answer to this is that there’s the **potential** for high storage requirements, but **only** if you plan to keep multiple snapshot versions on your system! Generally speaking, when you upgrade your system, you will have a new image to boot into after restart, as well as the previous stable version. It’s totally fine to have one or two previous system images on hand to boot from in case a change you make ends up being no-so-good. NixOS makes rollbacks so trivial, it's usually good practice to have a generation or two on hand to rollback to just in case.

If you’re a bit clingy and think it’s necessary to hold onto 10+ previous images, though, **you’re going to feel the weight of all that space being used up pretty quickly…**


![GRUB menu with previous configurations](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e9n466iokfjtbkwm4bsn.png)


With that question answered, there’s no other possible downsides for any of you to worry about other than your own willingness to learn about something new and awesome…


## Something Awesome Awaits
As a hardcore Arch Linux user, I was quite used to frequent rolling updates and library patches. I was also in the habit of regularly handling symlinks and ensuring executables were in my `$PATH`...which typically meant being located in the universal `/usr/bin` directory. To my surprise, among other things, was to learn that no such directory existed in NixOS...at least not in the traditional sense!

Everything as you know it when it comes to system paths and application directories will be completely flipped on its head with NixOS...and I'm talking some serious _Inception_ type stuff here folks!

In a typical Arch system, you run an upgrade command to update all of your applications:

```Bash
$ sudo pacman -Syu
```
During this process, any new versions of an application or library are downloaded and installed, replacing the old version. This applies to supporting modules and DLL’s too. Out with the old, in with the new! But what happens if your upgrade gets interrupted? Network disconnect, power surge, catastrophic shutdown cause of some weird possessed PC?? If you’re lucky, you are able to re-run the command and pick back up where you left off. Worst case, you get corrupted files, or have to fix pacman by unlocking it (among other possible scenarios)…this is no bueno!

With NixOS, updates are `atomic`, meaning that all update operations only get applied once the entire process has finished. If something gets interrupted or crashes during the update, no worries! No system files have been created/modified in any way whatsoever. This adds to the overall stability of the system!


![Nix Store - User Profiles](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/il4lu386d49te8wp7ufi.png)


**Personally, I always enjoyed having bleeding edge versions of many of the applications I’d regularly use.** As it turns out, NixOS has an `unstable channel` (a sources repo of sorts) that you can follow for all your system upgrades. This means you can have the stability of an immutable system, while also enjoying the newest versions of your favorite applications and tools!


## The Cherry On Top
So far, we’ve seen that NixOS has several qualities that should peak all of your interest, including:

- **Atomic, safe, system upgrades**
- **Snapshot-type versioning for quick-and-easy rollbacks (built-in!)**
- **Stable and Unstable (bleeding-edge) application sources to choose from**

All of these aspects are fine and dandy, but the real cherry on top is how the system itself is built and configured…that’s right, I said _**configured**_! NixOS isn’t some typical Linux system that you manage from the command line or GUI. It's an intricate, complex system that is **realized** and managed by a core configuration file (or flake depending on the setup)…**the glorious `configuration.nix`!**

Did you notice the file extension of the config file? That's right, _the OS has it's own programming language which it is built on top of!_ If you were unaware of its existence before now, it's okay, but the name should say it all...

## Package Manager | Language Framework
Nix is an interesting language, very similar to Haskell, and is the backbone of the operating system. I'm not going to get into it in this article, but will go a bit more in-depth in an upcoming article…so stay tuned and be sure to subscribe! As usual, I highly encourage anyone interested in the OS to at least spend a little time looking through the official [documentation and tutorials](https://nixos.org/learn.html) to get an idea of how it works.

At first, the thought of building out a configuration file to control what applications were installed on my machine seemed downright ludicrous! Why not just run commands from the terminal to install why I need? News flash..you can! **But** it's much more efficient and customizable to do so from the configuration file. Below is a small section that could be imported or written directly into the main config file. You'll notice it's pretty straightforward to understand, especially when declaring the `hostname` for the system and enabling `ssh` and `postgresql`:

```Nix
{ config, pkgs, ... }:

{
  fileSystems."/".device = "/dev/disk/by-label/nixos";

  networking.hostName = "mandark";

  environment.systemPackages = [ pkgs.firefox ];

  services.openssh.enable = true;
  services.openssh.forwardX11 = true;

  services.postgresql.enable = true;
  services.postgresql.enableTCPIP = true;

  services.xserver.enable = true;
  services.xserver.desktopManager.kde4.enable = true;
```

As it would soon turn out, using a configuration-based system is absolutely magnificent! Not only is it extremely powerful and flexible, it can be **reproduced** across machines! That’s right, I can tailor my own perfect system, and use the same configuration on my other devices to reproduce the _exact same_ setup with absolutely minimal effort! Even more awesome, I can build the new system on a beefy desktop PC and _push_ it over the network to a laptop and install everything there…**like I’m some kind of Nix Warlock!!!**

> It’s these final features that convinced me to give NixOS a worthy shot of being a daily driver on one of my laptops. **And before I knew it, I was running it daily on my main desktop and one of my Raspberry Pi’s as well!** Even now, I’m writing part of this article on it because it just works so darn well, regardless of how powerful your hardware is!

<br>
## Wrapping Up
There’s actually one other (freaking awesome) thing that can be done to make a NixOS system the best of the best that you can have on your device…**but you’ll have to stay tuned for that article!**

Whether you’re an Arch Linux power-user like me, or an intrepid newbie looking for the perfect OS to call home, I hope you take a moment to seriously look into NixOS. **It has the potential to be the paradigm shift that many of you have been looking for, and it’s community is only going to continue to grow!**


I hope you enjoyed a glimpse at my own personal experience and love for NixOS! Give me a like and leave a comment with your thoughts! **If you’re curious and want to learn more about various programming frameworks and systems like NixOS, feel free to follow me and subscribe for updates on newly released articles!**

## Until next time, stay curious and seek knowledge!
</br>
![By the way...](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ovrf759q24i5cnmrhu6c.png)
{% embed https://dev.to/dedsyn4ps3 %}
{% embed https://www.github.com/dedsyn4ps3?source=post_page-----d1b26dd3dc9c-------------------------------- %}