Welcome to the NixOS Crash Course! Think of this as the Ron Popeil approach to Linux: "Set it and forget it." While NixOS may have a steeper learning curve than other distributions, it rewards you with unparalleled reproducibility and flexibility.
This guide will walk you through setting up NixOS from a fresh install, customizing it with packages, and leveraging Home Manager for user-level configuration. Let’s get started!
NixOS is popular among:
- Developers and DevOps Engineers who love reproducible builds and deployments.
- Linux Enthusiasts who enjoy tweaking and customizing their setups.
- System Administrators looking for a declarative approach to configuration.
If you value consistency and want your configurations to work across machines, NixOS might be for you!
Before diving in, ensure you have:
- A fresh NixOS installation. If you’re new to NixOS, check out the official installation guide or simply download the ISO from here.
- Optional: A Linux-compatible Wi-Fi adapter like the Alfa AWUS036ACHM. NixOS requires an internet connection during installation. If you’re unsure whether your Wi-Fi card is supported by the Linux kernel, consider using an adapter.
- Make sure to allow un-free software during installation unless you’re certain you don’t need it. This typically helps with drivers and hardware compatibility.
- A willingness to tinker and learn!
Note: Some configurations, like for older MacBooks (e.g., a 2015 MacBook Air), may require additional setup for components like webcams.
Nix is a package manager, and NixOS is a Linux distribution built around it. Instead of manually managing configurations, you declare your system’s state in configuration files. Think of it as coding your system into existence.
Key concepts:
- Declarative Configuration: Define your system in files.
- Reproducibility: Replicate configurations on different machines.
- Atomic Upgrades and Rollbacks: Easily revert changes.
For editing configuration files, you’ll need a text editor. If Nano isn’t your preference, install Vim temporarily:
nix-shell -p vim
This creates a temporary shell with Vim, removed after the session ends.
Set your system’s hostname in /etc/nixos/configuration.nix
:
networking.hostName = "nebulaNugget";
Test the change:
sudo nixos-rebuild test
Apply it permanently:
sudo nixos-rebuild switch
Add packages under environment.systemPackages
in configuration.nix
:
environment.systemPackages = with pkgs; [
vim
wget
firefox
];
Rebuild your system:
sudo nixos-rebuild switch
Packages and options are found here. There are loads!:
For convenience, move your NixOS configuration directory to your home folder:
mkdir ~/etc
sudo mv /etc/nixos ~/etc/
sudo chown -R $(id -un):users ~/etc/nixos
sudo ln -s ~/etc/nixos /etc/
This lets you edit configurations without switching to root. I recommend initializing this folder as a private repository. This makes management really easy.
Home Manager allows you to manage user-level configurations declaratively. This method is installing Home Manager as a NixOS Module.
Add the Home Manager channel matching your NixOS version:
sudo nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.11.tar.gz home-manager
sudo nix-channel --update
Learn more about channels here.
Add the Home Manager module to imports:
imports = [
<home-manager/nixos>
];
Define user-specific configurations:
home-manager.users.phil = {
home.stateVersion = "24.11";
programs.vscode = {
enable = true;
package = pkgs.vscodium;
extensions = with pkgs.vscode-extensions; [
bbenoist.nix
kamadorueda.alejandra
];
};
programs.chromium = {
enable = true;
extensions = [
"nngceckbapebfimnlniiiahkandclblb" # Bitwarden extension ID
];
};
};
The VSCode extensions are from search.nixos.org, The Chrome extensions are the code at the end of its URL, like this for Bitwarden: nngceckbapebfimnlniiiahkandclblb
Apply changes:
sudo nixos-rebuild switch
Keep your system up to date:
sudo nix-channel --update
sudo nixos-rebuild switch --upgrade
Remove unused packages and generations:
sudo nix-collect-garbage -d
Learn more here.
If a configuration causes issues, revert to a previous generation via GRUB or:
sudo nix-env --rollback
- Official Documentation: NixOS Manual
- Community Wiki: NixOS Wiki
- Support: Join the NixOS Discourse or Matrix chat.
With this guide, you’re well on your way to mastering NixOS. Its declarative, reproducible approach can transform how you manage systems. Experiment, learn, and enjoy the journey!
Happy hacking!