DEV Community

Adithya K B
Adithya K B

Posted on

NixOS - A Unique Linux Distribution

NixOS is a purely declarative distro, where everything is configured in a configuration file located at /etc/nixos/configuration.nix.

What is NixOS??

  • There will also be a hardware-configuration.nix at the same location which you probably never have to touch. It is auto-generated during installation to handle hardware-specific configurations.
  • Every package you install and every change you want to make has to be done through the configuration.nix file.
  • If you want to find the name of the packages, this is where you search.
  • Everything you change in the configuration.nix file affects the whole system.
  • After you make changes to the config file, You need to rebuild your system for the changes to be applied. You can test the changes without rebuilding your system too. For rebuilding your system, You need to run sudo nixos-rebuild switch and to test the changes without rebuilding you can run sudo nixos-rebuild test
  • Every time you rebuild your system, a new generation of it is created. Each generation is like a savepoint of your system that you can revert back to. So even if you mess up your system, You can just switch back to a previous generation.

So what's nix?

  • Nix is a purely functional packet manager that is written mainly for configuration. If you check any config files in NixOS, they end in a .nix extension and has a similar structure
{pkgs,lib,...}:{
  programs.hyprland.enable = true;
}
Enter fullscreen mode Exit fullscreen mode
  • If you have any programming experience, just understand that every module or file written in nix is a single function returning a single output.
  • here {pkgs,lib,...}is the inputs to the function and {programs.hyprland.enable = true;} is the function body.
  • If you want to know more about nix, give it a try here

Flakes?

  • So the main selling point that NixOS gives it victims is that its reproducible and stable. Flakes is something that makes the system more stable.
  • As said earlier, The packages need to be defined in the configuration.nix for them to be installed but we don't mention the version of the packages there.
  • This is where the experimental yet highly used flake comes, In flakes you pin the version of the packages in a flake.lock file, so that later when you install flakes, you install the exact same version making the exact copy of the system.
  • Pinning or locking the version doesn't mean you can't update the packages. You can update the flake.lock by running the nix flake update command.

Home-Manager?

  • Well, I said NixOS is configured by writing and modifying 'a' configuration file right but nope, NixOS users decided to make more configuration files for it. (yeah, no life ik).
  • The changes in the configuration.nix file affects the whole system but the home-manager allows you to make changes for a particular user.
  • Yep, this means every user in your system can have a different DE or WM. That way you can sit and configure different user accounts and bring the chances of having a life to zero.
  • There are few settings that can be enabled only through the configuration.nix file.
  • You can find the options you can customize through home-manager here

Personal Views

The good part

  • Currently NixOS is the distro I'm daily driving and I'm loving it by far. The best thing is that it combines the rolling-release feature of of Arch with stability.
  • Since you define everything in a config file, you get to know exactly what's in your system.
  • The next best thing about it is its logo.
  • Since you can define all your configs, even for packages like waybar, rofi etc, it's much easier to rebuild the system. I can just take my dotfiles and just with a single command can get an exact copy of my system.
  • This is probably the best distro you can choose for ricing since switching to another WM or DE is just a matter of changing a line or two in configs.
  • I'm using hyprland along with NixOS. And this is how my setup currently looks like:

NixOS Setup

The not-so-good part

  • Not at all a beginner friendly distro. If you are gonna set this up for a newbie, they'll quit Linux.
  • The wiki's pretty bad.
  • You are configuring the system in a functional language. So if you are a programmer, learning it wouldn't be a big deal. But for someone with no idea about it, This part can be pretty tough.
  • Sometimes you feel like you are fighting the distro. I once had to set up a shell for rust for building a GUI which was a nightmare.
  • NixOS works much different from a normal linux distro. It is non FHS complaint and everything's in a config file. You can use packages without configuring the NixOS way too. But doing it the NixOS way might take a lot of time.

Summing Up

  • Overall, It's a great and unique distro but maybe not for everyone.
  • If you don't want to sit and configure your system, NixOS wouldn't be the best distro for you.
  • Configuring everything can be tough at the beginning but once you are done with it, You have got a stable system with repo of packages greater than AUR.
  • Great distro if you are into ricing.
  • Not beginner friendly.
  • Recency with stability.

Top comments (0)