Overview of installation methods#
NixOS offers several installation methods:
- Graphical installation (recommended for beginners)
- Minimal installation (recommended for advanced users)
- Virtual-machine installation (for testing)
- 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=fsyncWindows
3. Boot the installer#
- Insert the USB drive and boot from it
- Select NixOS Installer to enter the live environment
- Wait for the system to finish loading
4. Graphical installation (recommended for beginners)#
This is the simplest installation method:
- After booting, select Install NixOS
- Choose a language (Chinese is well supported)
- 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/boot5.2 Generate the initial configuration
# 生成配置
sudo nixos-generate-config --root /mnt
# 查看生成的配置
ls /mnt/etc/nixos/
# 应该包含:configuration.nix 和 hardware-configuration.nix5.3 Edit the configuration
sudo nano /mnt/etc/nixos/configuration.nixKey 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-installnixos-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
exit5.5 Reboot
sudo reboot6. 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 dhcpcdDisk detection issues
# 加载更多磁盘驱动
sudo modprobe nvme
sudo modprobe sd_modHow 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 switchInitial 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 --upgrade2. Install commonly used software
Edit /etc/nixos/configuration.nix:
environment.systemPackages = with pkgs; [
vim
git
firefox
htop
wget
curl
];Then rebuild:
sudo nixos-rebuild switch3. Enable flakes (recommended)
nix.settings.experimental-features = [ "nix-command" "flakes" ];Reference resources#
References & further reading
Adapted from technical notes. Examples use generic names.
Continue along a reading path
NixOS system foundations and configuration
- 01NixOS: the foundations of a declarative system
- 02Installing NixOS: installation media, partitions, and initial configuration
- 03NixOS configuration basics: options and modules
- 04Managing a system with Flakes and Home Manager
- 05The NixOS command line: old and new interfaces and everyday maintenance
- 06NixOS generation management and garbage collection
- 07Specialisation: multiple configuration variants in one generation
- 08If configuration is reproducible, why do apps still forget?