NixOS installation guide

Configurare noua (How To)

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.

Part 2 – Booting
  1. Boot from the installation USB.
  2. Select the graphical installer or minimal installer.
  3. Open a terminal.

Become root if necessary:

sudo -i

Confirm networking:

ping nixos.org
Part 3 – Identify Storage

List disks:

lsblk

Example:

nvme0n1
├─nvme0n1p1
├─nvme0n1p2

Assume:

Disk:
/dev/nvme0n1
Part 4 – Partitioning

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%
Part 5 – Filesystems

Format EFI:

mkfs.fat -F32 /dev/nvme0n1p1

Format root:

mkfs.ext4 /dev/nvme0n1p2
Part 6 – Mount
mount /dev/nvme0n1p2 /mnt

mkdir -p /mnt/boot

mount /dev/nvme0n1p1 /mnt/boot
Part 7 – Generate Configuration
nixos-generate-config --root /mnt

Files created:

/mnt/etc/nixos/configuration.nix

/mnt/etc/nixos/hardware-configuration.nix
Part 8 – Initial Configuration

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";
}
Part 9 – Install
nixos-install

Set root password.

Reboot:

reboot

Remove the USB.

Part 10 – Enable Flakes

Edit:

/etc/nixos/configuration.nix

Add:

nix.settings.experimental-features = [
  "nix-command"
  "flakes"
];

Rebuild:

sudo nixos-rebuild switch
Part 11 – Convert to Flake

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
Part 12 – Install Packages

Temporarily:

nix shell nixpkgs#ripgrep

Run once:

nix run nixpkgs#hello

Permanent:

environment.systemPackages = with pkgs; [
  firefox
  git
  neovim
  ripgrep
  fd
  htop
  tmux
];
Part 13 – Home Manager

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
Part 14 – Garbage Collection

Delete old generations:

sudo nix-collect-garbage -d

Automatic cleanup:

nix.gc = {
  automatic = true;
  dates = "weekly";
  options = "--delete-older-than 30d";
};
Part 15 – Rollbacks

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.

Part 16 – System Upgrades

Update flake inputs:

nix flake update

Apply:

sudo nixos-rebuild switch --flake /etc/nixos
Part 17 – Useful Services

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;
Part 18 – Development

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
Part 19 – Recommended Repository Layout
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.

Part 20 – Troubleshooting

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.

Solutie

Tip solutie

Permanent

Voteaza

(1 din 2 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?