NixOS: A Perfect Linux Distro (for me)


ABSTRACT: This blog post is going to cover few experiences I had with Nix and NixOS which I had been daily-driving for past 6months. The experience has been really mixed. NixOS is a Linux distribution (or Distro) that uses nix as its package manager. Nix is a functional programming language which was solely developed to maintain packages and derivations in the early 2003.

Early Phases

The early phases of me working with nix was mostly in doubt and was constantly meeting roadblocks due to the lack of documentation about certain architectural ways. I started out with using a normal NixOS configuration where I have a configuration.nix and hardware-configurations.nix which is generated by the nixos-generate-config command-line tool. I opted for a GNOME for the first time and I was able to easily do that by just adding a line to the configuration.nix as:

services.xserver = {
  enable = true;
  gnome.enable = true;
  gdm.enable = true;
}

Later, once I was bored with the GNOME in general due to its lacking window management options to tile windows and the bloat it had pre-installed. This made me go for a new shiny Wayland Compositor that the cool kids have been trying out Hyprland. This was initially a tough process as I was unaware of what changes Wayland has brought forward with time. This was also my first time checking wayland out. Upon simply using nix-shell -p hyprland --run Hyprland in a tty, I was able to run Hyprland without much issue and test it out. I made the initial configuration for my three-monitor setup and was successfull with it. Once I was comfortable with Hyprland, I decided to remove gnome completely and did a garbage collect using nix gc but with sudo. This caused chaos and cleared out my complete nix store which means /nix/store was now empty and now I dont have even a single package installed and working. I could not even run nix commands as it removed nix from the store as well. That was the moment I realized that I had made a huge mistake.

The Come-Back

After trying out all the options without success in my botched install of NixOS, I decided to reinstall NixOS but this time, I’ll use sudo much more carefully. Now, the install went smooth and i had a working Hyprland instance for me. I like to game when Im very bored or feels unmotivated to do anything, which was mostly DiRT Rally 2, EA Sports WRC, Counter Strike 2 etc. In the Hyprland instance, I recognized that my games does not work as expected due to some incompatibilities from the Wayland side. So I installed XFCE on side to enjoy the X11 benefits while I need it. This has helped me out a lot as some applications were simply not launching in Wayland. This is when I really put myself into learning the master layout and found that it suited my workflow immensely better than the dwindle layout. I also learned a lot how Hyprland works since then.

Flakes: An Unsung Hero or Complete TimeWaste

Once I had the complete system working and in good shape, I decided to jump on the journey to learn what flakes in nix are and how useful they are for development. I was using the nix-shell till this point to add dependencies for my projects. Flakes was certainely a very good and challenging experience for me at first. This constant need to update my knowledge about what flake is and its syntax seemed wierd to me at first. But when I was able to read normal flakes for the functions that they are, I was able to reuse flake very easily. An unofficial book named NixOS with Flakes (Unofficial) helped me understand the integral parts of flake.

       |-> Inputs
       |
Flake -|-> Outputs
       |
       |-> Derivation

Flake is essentially a middle-man who locks dependencies to a pinned version and also gives us the ability to run any flake using the nix flake command using the nix package manager. This gives us better control over the declaration of dependencies in our system. During the time when I was running Arch Linux, one of the major issues I have had with it was not having a correct list of installed packages and how one depends to another. But, in NixOS all packages are defined as a declaration which can be later viewed and updated to your liking and can also see exactly what packages are being used. You are also able to write custom derivations of applications. My first attempt at this was to write a derivation for Thrustmaster T300 which is a sim-racing steering base and wheel. The derivation was successfully made into a PR on the nixpkgs repository to add the same to linux kernel packages.

Still Learning..

Although this journey of ups and downs in NixOS have been exhausting, I am very much satisfied with it (even though I managed to fry up my installation two times due to lack of knowledge and clumsiness). Right now, I still have Hyprland and XFCE installed on my main computer but my NixOS configuration has been extended to include devices that was with me such as my laptop, raspberry pi 400 etc. I still believe that there is a lot to learn and I am ready to go on a Nix journey again as its very educational and enjoyable.

Conclusion

  • NixOS is the best distro I have used till date.
  • It is always skill issue that strikes before anything else. But keep believeing in yourself.
  • Thanks for reading. Enjoy and Have a nice day!

References