NixOS - A Unique Linux Distribution
My Experience Using NixOS
NixOS - A Unique Linux Distribution
What is NixOS?
- NixOS is a declarative Linux distribution. It is based on the Nix package manager, allowing reproducibility and portability.
- It’s different from other distributions because of its non-FHS compliance and configuration.
- The whole configuration for the system is written inside a single configuration file
configuration.nix
. You can also find ahardware-configuration.nix
, which you probably never have to edit. It contains the configuration for the hardware. - After modifying the configuration files, you can run
sudo nixos-rebuild switch
to apply the changes orsudo nixos-rebuild test
to test the changes. - The
nixos-rebuild switch
command creates a new generation. So, in case the system breaks, you can roll back to a previous generation.What is Nix?
- Nix is a purely functional package manager that allows for declarative installation of packages.
- Nix can be used as a package manager, not just in NixOS, but in other Linux distributions and even in macOS.
- Packages in Nix are built from Nix expressions, which is a simple functional language.
- It allows multiple versions of the same package to be installed. Due to its hashing scheme, they don’t interfere with each other.
- If you want to learn more about Nix, check out nix pills
What is Flakes?
- Flakes is an experimental yet popular feature in NixOS that allows the pinning of versions of dependencies, making the system more reproducible.
- The version is pinned in a
flake.lock
file, and the flake expression is written in aflake.nix
file. - The pinned versions can be updated to a higher version with the
nix flake update
command.What is Home-Manager?
- Home-Manager helps in managing the user environment using the Nix package manager.
- Home-Manager can be installed as a module or a standalone tool.
- It allows you to configure user-specific utilities. For example, you can write the config for Hyprland using Home-Manager so that when you build the system, the configs will be applied automatically.
- Here is an example of my ghostty config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
{...}: { programs.ghostty = { enable = true; settings = { theme = "catppuccin-mocha"; font-size = 13; background-opacity = 0.8; font-family = "JetBrainsMono NF"; cursor-style = "bar"; window-padding-x = 10; window-padding-y = 10; confirm-close-surface = false; }; }; }
Views
- I personally think NixOS is a great Linux distribution that combines stability and recency.
- Since it’s non-FHS compliant, it might be hard switching to it initially. But once you get the hang of it, you’re good to go.
- This might be the best distro for ricing since you can rice without the fear of breaking your system. If you do break it, just roll back.
- I did have issues setting a few things up, which I can say was a nightmare.
- Not at all a beginner-friendly distro.
- The learning curve is very steep, but that depends on how deep you go. NixOS can be a rabbit hole.
- You will have an exact idea of what’s on your system since you are configuring almost everything declaratively.
- Best logo of all distros.
Notes
Note 1
- If you want to, say, set the GTK icon theme using the home-manager, you can fetch the package from nixpkgs but you may not know the exact theme name.
- Example
1 2
iconTheme.package = pkgs.dracula-icon-theme; iconTheme.name = "Dracula";
- Here you may not know the exact theme name to pass to the
iconTheme.name
. To get the name, you can fetch the package and check the contents of it using the following command.1
cd $(nix build nixpkgs#dracula-icon-theme --print-out-paths --no-link)
- This command lets you check the contents of the theme folder and get the exact theme name from it.
- From this we can understand that the con theme name is Dracula.
Note 2
- This is a great website if you want to check what options are available for a particular package - https://mynixos.com/
Note 3
- Some themes or packages allow you to choose particular flavours to be installed instead of the whole theme/package.
- For example, the fluent GTK theme allows you to install particular flavours.
- You can select these specific flavours using the override option.
1 2 3 4 5 6
pkgs.fluent-gtk-theme.override { themeVariants = [ "purple" ]; colorVariants = [ "dark" ]; sizeVariants = [ "compact" ]; tweaks = [ "round" "noborder" ]; }
Note 4
- Some of the apps or themes that you need may not be available in nixpkgs. In such a situation, you will have to write your own nix derivation for it.
- Here is a resource you can reference for writing your own derivation - write your own derivation
Note 5
- In NixOS, you will generally use dev shells for setting up the development environment. The nix way of setting up a development environment is to create a dev shell.
- For example, for web development, you don’t install Bun/Node globally. Instead you write a flake that activates a shell env with Node/Bun in it.
- Here is a collection of dev shell templates - nix dev shell templates
Note 6
- You can also build your own NixOS Installer ISO, So that all your configs will be applied as soon as you install NixOS.
- I’ll link Vimjoyer’s video on this. He does great content on NixOS. Vimjoyer’s Video
Note 7
- When you modularize your NixOS config and write the config for each package in a separate file, make sure the file is staged before you run
sudo nixos-rebuild switch
orhome-manager switch
if the directory is git initialized. - Or else Nix will throw an error that the file does not exist, even though it does.
Note 8
- You can also temporarily install packages with
nix-shell -p <packageName>
. These packages only exist temporarily inside that particular shell. They are not installed globally. - Here is an example
- Here, Microfetch by raf (also check out nvf by raf if you use neovim) is installed using nix-shell, which is only available in that particular shell.
Config
- Here’s my config
- Nixos Hyprland Config - Config
- Gnome
- Hyprland
This post is licensed under CC BY 4.0 by the author.