DEV Community

Cover image for 5 Very Common Mistakes a beginner should avoid when trying NixOS for the first time to truly start daily driving it.
Beck Mateo
Beck Mateo

Posted on

5 Very Common Mistakes a beginner should avoid when trying NixOS for the first time to truly start daily driving it.

Introduction

There are many ways to use NixOS, the one most people start with is probably why they quit when they use it for first time (myself included), so if you're a beginner looking to daily drive NixOS on your personal or work device then here are 5 mistakes you should avoid to make sure to have a smooth sailing

Completely ignoring garbage collection

This is by far the most common mistake.

Garbage collection means getting rid of the package versions that are no longer used, it's important because leaving the fifty something versions of a package will quickly cram up your disk space
Garbage collection is very easy on NixOS, it can be done using the following command
nix-collect-garbage
You can even add the -d argument to delete older generations
Or you can add the following lines to your /etc/nixos/configuration.nix to make garbage collection automated

nix.gc = {
  automatic = true;
  dates = "weekly";
  options = "--delete-older-than 30d";
};
Enter fullscreen mode Exit fullscreen mode

This is something that I didn't know how to do when I first installed NixOS and it frustrated me because my disk space never seemed to free up when trying to clear my cache!, that's why you should regularly clean up your garbage if you want to have space for the actual important stuff especially if you're using a small storage drive

Using nix-env to install packages

This is an abnormally common mistake
If the whole point of using NixOS is to have a declarative system , then going in and using nix-env to install packages feels like the most counter-intuitive thing to do, this is because :

  1. You lose track of what packages you installed (just like on a regular Linux Distro)
  2. You can't really change the configuration options of this package declaratively either

This can easily be avoided my simply adding the package name to the packages section of your /etc/nixos/configuration.nix

  users.groups.media = {};
  users.users.username = {
    isNormalUser = true;
    description = "username";
    extraGroups = [ "networkmanager" "wheel" "libvirtd" "media" ];
    packages = with pkgs; [
      package_name ];
Enter fullscreen mode Exit fullscreen mode

If you just want a package temporarily, then what I recommend this using the nix-env which creates a temporary shell for the installed package which then gets deleted once you close the terminal
nix-shell -p package_name

The takeaway here is that there are better ways to install packages on your NixOS than just using the classic package manager install approach , this helps your system to be more organized and less prone to just randomly breaking

Not reading the available documentation

This is a mistake that most people in make in general.

Reading the documentation is crucial to understanding how a certain piece of software work , it's not just some random gibberish , it contains the instructions on how to efficiently use and configure it and even if you're a complete beginner, there's always a Getting Started section at the start of every online to help you along the way, for NixOS, the best way to start is the
NixOS Manual

There's also the NixOS unofficial wiki which contains useful information on certain topics like configuring the NVIDIA drivers, and using different desktop environments like GNOME or KDE Plasma.
NixOS Wiki

I know that NixOS isn't the best when it comes to documentation but having something to work with is much better than trying to just randomly press buttons and hope things work out

Not searching for configuration options

This is another one that'll save you a lot of time and hassle

Instead of trying to do thing the classic way like like configuring you firewall or keyd manually, you can instead use NixOS options to do so in your configuration files, if you want to know what options you can put in your /etc/nixos/configuration.nix just search on NixOS options to get a list of available options with their default values, combine that with some information from the wiki and you won't have to edit multiple config files just to optimize your system, you can just do all of it from you config file.

This is a much better and efficient way to manage your NixOS than just doing things manually and then forgetting what you did or not remembering where the configuration file (this happened a lot to me too)

Trying to jump on the Flakes ship way too soon

Flakes can an amazing tool to manage your NixOS.

However, they can be very frustrating to deal with if you don't exactly know what you're doing, they're also still considered to be an experimental option and the documentation still needs some work. For this reason, I recommend that you completely avoid using Flakes if you're a beginner and just stick to editing you /etc/nixos/configuration.nix to do must things and then after you become fluent in the Nix language should you start looking into Flakes and experimenting with them.

Conclusion

NixOS is an amazing system and getting to know it can be a very rewarding but the pitfalls are plenty , much more than the ones mentioned here , and this can leave a beginner totally frustrated , in this article, I tried to clarify some of the most common ones to help future users avoid them.

Top comments (0)