Situatie
NixOS is a Linux distribution built around the Nix package manager, where the entire operating system is described as code. Instead of manually installing software and editing configuration files, you define your desired system state in configuration files.
Advantages include:
- Fully reproducible systems
- Atomic upgrades and rollbacks
- Declarative package management
- Reliable dependency isolation
- Easy migration between machines
- Excellent development environments
Part 1 – Preparation
Requirements
- 8 GB RAM minimum (16 GB recommended)
- 30+ GB storage
- USB flash drive (4 GB or larger)
- Internet connection
- UEFI firmware (recommended)
Download the latest NixOS ISO and verify its checksum before writing it to a USB drive.
- Boot from the installation USB.
- Select the graphical installer or minimal installer.
- Open a terminal.
Become root if necessary:
sudo -i
Confirm networking:
ping nixos.org
List disks:
lsblk
Example:
nvme0n1
├─nvme0n1p1
├─nvme0n1p2
Assume:
Disk:
/dev/nvme0n1
Using GPT:
parted /dev/nvme0n1 -- mklabel gpt
EFI partition:
parted /dev/nvme0n1 -- mkpart ESP fat32 1MiB 512MiB
parted /dev/nvme0n1 -- set 1 esp on
Root:
parted /dev/nvme0n1 -- mkpart primary 512MiB 100%
Format EFI:
mkfs.fat -F32 /dev/nvme0n1p1
Format root:
mkfs.ext4 /dev/nvme0n1p2
mount /dev/nvme0n1p2 /mnt
mkdir -p /mnt/boot
mount /dev/nvme0n1p1 /mnt/boot
nixos-generate-config --root /mnt
Files created:
/mnt/etc/nixos/configuration.nix
/mnt/etc/nixos/hardware-configuration.nix
Edit:
nano /mnt/etc/nixos/configuration.nix
Example:
{ config, pkgs, ... }:
{
imports = [
./hardware-configuration.nix
];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
networking.hostName = "desktop";
time.timeZone = "Europe/Bucharest";
i18n.defaultLocale = "en_US.UTF-8";
services.xserver.enable = true;
services.displayManager.gdm.enable = true;
services.desktopManager.gnome.enable = true;
users.users.alex = {
isNormalUser = true;
extraGroups = [ "wheel" "networkmanager" ];
};
networking.networkmanager.enable = true;
environment.systemPackages = with pkgs; [
git
vim
wget
curl
];
system.stateVersion = "26.05";
}
nixos-install
Set root password.
Reboot:
reboot
Remove the USB.
Edit:
/etc/nixos/configuration.nix
Add:
nix.settings.experimental-features = [
"nix-command"
"flakes"
];
Rebuild:
sudo nixos-rebuild switch
Directory:
/etc/nixos
Create:
flake.nix
Example:
{
description = "Desktop";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
{
nixosConfigurations.desktop =
nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
];
};
};
}
Rebuild:
sudo nixos-rebuild switch --flake /etc/nixos#desktop
Temporarily:
nix shell nixpkgs#ripgrep
Run once:
nix run nixpkgs#hello
Permanent:
environment.systemPackages = with pkgs; [
firefox
git
neovim
ripgrep
fd
htop
tmux
];
Install Home Manager as a flake input.
Benefits:
- User configuration as code
- Dotfile management
- Reproducible shell configuration
- Declarative editor setup
- Version-controlled user environment
Example modules:
- Git
- Zsh
- Bash
- Neovim
- Alacritty
- Kitty
- VS Code
- SSH
- GPG
- Starship
Delete old generations:
sudo nix-collect-garbage -d
Automatic cleanup:
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 30d";
};
List generations:
sudo nix profile history
Rollback:
sudo nixos-rebuild switch --rollback
You can also select previous system generations directly from the bootloader if a rebuild prevents the system from booting.
Update flake inputs:
nix flake update
Apply:
sudo nixos-rebuild switch --flake /etc/nixos
SSH:
services.openssh.enable = true;
Docker:
virtualisation.docker.enable = true;
PipeWire:
services.pipewire = {
enable = true;
pulse.enable = true;
};
Printing:
services.printing.enable = true;
Bluetooth:
hardware.bluetooth.enable = true;
Example development shell:
{
description = "Example dev shell";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }:
let
pkgs = import nixpkgs {
system = "x86_64-linux";
};
in {
devShells.x86_64-linux.default =
pkgs.mkShell {
packages = with pkgs; [
git
gcc
cmake
python3
];
};
}
Enter:
nix develop
nixos/
├── flake.nix
├── flake.lock
├── hosts/
│ └── desktop
├── modules/
│ ├── networking.nix
│ ├── users.nix
│ ├── desktop.nix
│ ├── fonts.nix
│ └── services.nix
├── home/
│ ├── git.nix
│ ├── shell.nix
│ ├── nvim.nix
│ └── zsh.nix
Keeping configuration modular makes it easier to reuse components across multiple systems and simplifies maintenance.
Configuration errors
Validate before switching:
sudo nixos-rebuild test
Boot issues
- Confirm the EFI partition is mounted at
/boot. - Verify
boot.loader.systemd-boot.enable = true;. - Ensure UEFI mode is enabled in firmware.
Network problems
Verify NetworkManager:
systemctl status NetworkManager
Flake errors
Refresh lock file:
nix flake update
Or remove flake.lock and regenerate it if dependency resolution becomes inconsistent.
Leave A Comment?