OFFSET偏移
← All articlesOFFSET / FIELD NOTESNO. 014

Installing NixOS: installation media, partitions, and initial configuration

Understand prerequisites and steps for both graphical and manual installation.

English translation · Code and commands follow the Chinese original.

IN THESE READING PATHSNixOS system foundations and configuration ↗
About 4 min readStart reading

Overview of installation methods#

NixOS offers several installation methods:

  1. Graphical installation (recommended for beginners)
  2. Minimal installation (recommended for advanced users)
  3. Virtual-machine installation (for testing)
  4. Remote server installation (for headless systems)

1. Download an installation image#

Visit the NixOS download page:

Image type Recommended use
GNOME ( graphical ) Desktop users
Plasma Desktop KDE desktop users
Minimal (64-bit Intel/AMD) Servers and advanced users

2. Create a bootable drive#

Writing the image overwrites the target device. First verify its capacity, model, and mount status, and unmount the target USB drive’s partitions. /dev/sdX is a placeholder that must be replaced with the whole USB drive, never the system drive.

Linux (on macOS, adjust disk identifiers and arguments for the platform)

# 查找 U 盘设备名(如 /dev/sdb)
lsblk

# 写入镜像(替换 /dev/sdX 为你的设备)
sudo dd if=nixos-graphical.iso of=/dev/sdX bs=4M status=progress conv=fsync

Windows

Use Rufus or Ventoy.

3. Boot the installer#

  1. Insert the USB drive and boot from it
  2. Select NixOS Installer to enter the live environment
  3. Wait for the system to finish loading

4. Graphical installation (recommended for beginners)#

This is the simplest installation method:

  1. After booting, select Install NixOS
  2. Choose a language (Chinese is well supported)
  3. Follow the wizard to complete:
    • Partition setup
    • User creation
    • System configuration

Partitioning suggestions

Partition Size Filesystem Mount point
EFI partition 512MB FAT32 /boot (this example uses systemd-boot)
Root partition 50GB+ ext4/btrfs /
Swap partition Determine based on hibernation requirements and memory load swap -
Home directory Remaining space ext4/btrfs /home

5. Command-line installation (advanced)#

5.1 Partitioning and formatting

The following is only an example for a test disk that has been backed up and explicitly approved for erasure. Device numbering varies by machine, and NVMe names are different too; do not copy these commands directly onto a disk containing data. For UEFI, create a GPT partition table, an EFI System Partition, and a root partition, ensuring that formatting and mount targets correspond.

# 查看磁盘
lsblk

# 分区(以 /dev/sda 为例)
sudo fdisk /dev/sda
# 创建 EFI 分区 (512MB)
# 创建根分区

# 格式化
sudo mkfs.fat -F 32 /dev/sda1  # EFI
sudo mkfs.ext4 /dev/sda2       # 根分区

# 挂载
sudo mount /dev/sda2 /mnt
sudo mkdir -p /mnt/boot
sudo mount /dev/sda1 /mnt/boot

5.2 Generate the initial configuration

# 生成配置
sudo nixos-generate-config --root /mnt

# 查看生成的配置
ls /mnt/etc/nixos/
# 应该包含:configuration.nix 和 hardware-configuration.nix

5.3 Edit the configuration

sudo nano /mnt/etc/nixos/configuration.nix

Key configuration options:

{ config, pkgs, ... }:
{
  imports = [
    ./hardware-configuration.nix
  ];

  # 引导配置
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  # 网络配置
  networking.hostName = "workstation";
  networking.networkmanager.enable = true;

  # 时区和本地化
  time.timeZone = "Asia/Shanghai";
  i18n.defaultLocale = "zh_CN.UTF-8";

  # 桌面环境(可选)
  services.xserver.enable = true;
  services.displayManager.gdm.enable = true;
  services.desktopManager.gnome.enable = true;

  # 创建用户
  users.users.alice = {
    isNormalUser = true;
    extraGroups = [ "wheel" "networkmanager" ];
    # 安装时交互设置密码;不要将明文密码写入公开配置。
  };

  # 允许普通用户使用 sudo
  security.sudo.wheelNeedsPassword = true;

  # 新安装使用生成配置中的值;后续升级不要跟着发行版随意改。
  system.stateVersion = "26.05";
}

5.4 Run the installation

sudo nixos-install

nixos-install normally prompts you to set the target system’s root password, unless that step is disabled. An ordinary passwd command in the live environment changes that environment rather than the installed system. To set a target user’s password, mount the target system and enter it:

sudo nixos-enter --root /mnt
passwd alice
exit

5.5 Reboot

sudo reboot

6. Common issues#

Network interface names, network tools, and drivers depend on the installation media. Replace eth0 in the examples as appropriate. First identify the interface and any network management services already running to avoid starting multiple DHCP clients.

Installation media will not boot

  • Check the BIOS/UEFI settings and ensure UEFI mode is enabled
  • Disable Secure Boot

Network connectivity issues

# 查看网络接口
ip link

# 启用网络
sudo ip link set eth0 up
sudo dhcpcd

Disk detection issues

# 加载更多磁盘驱动
sudo modprobe nvme
sudo modprobe sd_mod

How to reinstall after modifying the configuration

# 挂载分区(如之前步骤)
sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot

# 切换到已挂载的目标系统
sudo nixos-enter --root /mnt

# 修改配置
nano /etc/nixos/configuration.nix

# 重新构建
nixos-rebuild switch

Initial configuration after installation#

The following switch examples activate the system. Use nixos-rebuild build when you only need to verify that it builds. For channels, update with --upgrade. For flake configurations, first update and review flake.lock, then rebuild from that lock file.

1. Update the system

sudo nixos-rebuild switch --upgrade

2. Install commonly used software

Edit /etc/nixos/configuration.nix:

environment.systemPackages = with pkgs; [
  vim
  git
  firefox
  htop
  wget
  curl
];

Then rebuild:

sudo nixos-rebuild switch

3. Enable flakes (recommended)

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

Reference resources#



References & further reading

  1. NixOS manual ↗
  2. Nix language manual ↗

Adapted from technical notes. Examples use generic names.

Continue along a reading path

NixOS system foundations and configuration

  1. 01NixOS: the foundations of a declarative system
  2. 02Installing NixOS: installation media, partitions, and initial configuration
  3. 03NixOS configuration basics: options and modules
  4. 04Managing a system with Flakes and Home Manager
  5. 05The NixOS command line: old and new interfaces and everyday maintenance
  6. 06NixOS generation management and garbage collection
  7. 07Specialisation: multiple configuration variants in one generation
  8. 08If configuration is reproducible, why do apps still forget?
CONTINUE READING / NEXT ARTICLENixOS configuration basics: options and modules

Organize a system configuration around boot, networking, users, packages, and services.