Part 2: Installing NixOS & Understanding the Config
I highly recommend doing your first installation on a Virtual Machine (VM) or an old laptop. Why? Because if you decide NixOS isn't for you, you can just nuke the VM or wipe the drive. No harm, no foul.
Getting the ISO
First, grab the NixOS ISO from the official download page.
For this tutorial, we will use the Minimal ISO. This might sound scary, but don't worry—the installation process still uses a graphical interface. We choose the minimal image because it forces us to build our system from the ground up, giving you a much better understanding of how the config works.
Flash it to a USB drive using your tool of choice (I prefer Balena Etcher).
Installing
In the past, installing NixOS was a command-line nightmare. Today, it uses Calamares, a graphical installer that looks exactly like the one on Ubuntu or Fedora. You click "Next," choose your timezone, pick your disk, and wait for it to do its thing.
Once you reboot, however, we lose the graphical interface. We are in terminal land now. This is where the initial weirdness of NixOS begins.
The first problem? The minimal image is bare. We don't have any programs installed. Not even Vim. We don't have apt or pacman. We have Nix.
So, how do we install software? You can technically launch a shell with a package available temporarily by running:
nix-shell -p package_name
But how do you find the package name? There are a couple of ways. The terminal way is to run nix-env -qaP <term>, but that is slow and inefficient because it evaluates the entire package tree.
Personally I always use search.nixos.org. It’s faster, gives you the exact attribute name, and tells you where it fits in the config.
For me, the first priority is Neovim (because I can't take Nano seriously). So, to get a temporary editor to edit our config:
nix-shell -p neovim
Now we have Neovim. But here is the catch: it is temporary. If you reboot now, Neovim disappears. nix-shell just plops you into an environment where the program is available for that session. It’s great for testing, but it’s not how we manage a system.
To make things permanent, we need to understand where files actually live.
Where is everything? (The read-only filesystem)
In a traditional Linux distro, if you install Firefox, its binary goes to /usr/bin/firefox and its config to /etc. In NixOS, those directories are basically empty.
Instead, everything lives in The Nix Store (/nix/store). If you list that directory, you will see thousands of folders that look like this:
/nix/store/h19lnffd...-firefox-120.0.1
/nix/store/a28bdj...-glibc-2.38
/nix/store/k82nb...-nodejs-18.1
This directory is the secret sauce because it contains all the files needed for a software to run. This allows you to have:
- Version Isolation: You can have Firefox 120 and Firefox 119 installed side-by-side. They live in different folders with unique hashes.
- Immutability: You cannot edit these files. Try
sudo rmorvimon a file in the store. You can't. This prevents accidental breakage.
"So how do I run programs?" NixOS uses Symlinks (shortcuts). When you "install" Firefox, NixOS creates a symlink from /run/current-system/sw/bin/firefox pointing to the specific hash in the store. Your system is essentially a web of shortcuts pointing to read-only data.
The two files that matter
Enough theory. Let's look at the "Blueprint" we talked about in Part 1. Head to /etc/nixos/. You will see two text files. These are the DNA of your computer.
hardware-configuration.nixconfiguration.nix
hardware-configuration.nix
This file was auto-generated during installation. It detects your disk drives, file systems, and CPU kernel modules. Do not touch this file manually. The first line of this file is pretty clear:
# Do not modify this file! It was generated by ‘nixos-generate-config’...
The only time you really need to worry about hardware quirks is if something isn't working out of the box. In that case, instead of hacking this file, I recommend checking the NixOS Hardware Repository. It contains pre-made configurations for specific laptops (Dell XPS, Lenovo ThinkPad, Macs, etc.). If you have hardware issues, look there first.
configuration.nix
This is where you live. This file controls everything. Right now, it looks like a mix of code and comments. It uses the Nix Language, which you can think of as "JSON with functions."
You only need to recognize three shapes to start:
# Attribute: How we SET things
path.subpath = value;
# List: Ordered elements (packages, firewall ports)
anotherPath.subpath = [ 10 20 30 ];
# Set: Like Objects or Dictionaries (key-value pairs)
yetAnotherPath = {
subpath = [ 10 20 30 ];
};
We will deep dive into the syntax in Part 3, but this is enough to be dangerous.
Your first edit: Installing a package
Let's change the state of the system by permanently installing neovim. Open /etc/nixos/configuration.nix (using the temporary nix-shell -p neovim we launched earlier).
Scroll down to environment.systemPackages. It should look something like this:
environment.systemPackages = with pkgs; [
# vim
# wget
neovim # <--- Add this line
];
Note: The with pkgs; keyword just saves us from typing pkgs.neovim, pkgs.git, etc.
Save the file. Now, apply the changes:
sudo nixos-rebuild switch
This command reads your blueprint, downloads the necessary hashes from the cache, builds the new system state, and switches to it live. If you exit your shell and try running nvim, it works. If you reboot, it will still be there.
The safety net: generations
Now for the best part. Reboot your computer. Look at the boot menu. You will see something like:
- NixOS - Generation 2 (current)
- NixOS - Generation 1
Every time you run nixos-rebuild switch, you create a new Generation. If you edit your config, mess up your graphics drivers, and reboot to a black screen:
- Hard reset the machine.
- Select "Generation 1" in the boot menu.
- You are back. The system is exactly as it was before you broke it.
Next Steps
Now that you have a running system and a text editor, the real fun begins. In the next article, we will look at the Nix Language itself, so you can stop copy-pasting and start understanding what you are actually writing.
Next step: 03 Nix Language
Previous step: 01 Philosophy
Go back to the index: Nixology