NixOS Installation Guide
This article explains how to install the command-line version (Minimal) of NixOS. NixOS is a Linux distribution based on the Nix package manager, featuring declarative configuration and other unique characteristics.
Preparation Before Installation
Prepare a Bootable NixOS USB
Download the ISO
Go to the NixOS official website to download the latest NixOS ISO. Choose the Minimal version. Alternatively, use the following links to download directly:
- NixOS 24.11 Minimal ISO for amd64
- SHA-256
Create a Bootable USB
It is recommended to use Ventoy to create a bootable USB. Ventoy supports multiple operating system ISOs and allows you to store multiple ISOs on the same USB. Simply copy the downloaded and verified NixOS ISO to the Ventoy-created USB.
Installation
Boot your computer from the USB and select NixOS to enter the installation interface.
Using SSH for Remote Connection
Since the default passwords for both nixos
and root
users are empty, set a password using the passwd
command before connecting via SSH. You can then connect to the NixOS installation interface from another computer using SSH.
1 | # Set a password for the current user (default is nixos) |
Check Network Connection
Use the ping
command to check if the network connection is working:
1 | ping -c 5 ping.ui.com |
Partition the Disk
Use the parted
command to partition the disk.
Back up your data before partitioning, as partitioning will erase all data on the disk.
Assume the disk for installing NixOS is /dev/nvme0n1
, and you want to use the btrfs
file system for the root directory. Use the following commands to partition the disk:
1 | $ sudo parted /dev/nvme0n1 |
After partitioning, format the partitions:
1 | # Format the EFI partition |
Since we are using the btrfs
file system, create subvolumes as needed. Here is an example of creating an @
subvolume:
1 | # Mount the root partition |
Mount the Partitions
1 | # Mount the root partition to /mnt using the @ subvolume and enable zstd:1 compression |
Generate and Adjust NixOS Configuration Files
Use the sudo nixos-generate-config --root /mnt
command to generate NixOS configuration files.
/mnt/etc/nixos/hardware-configuration.nix
: Hardware configuration file containing system hardware information./mnt/etc/nixos/configuration.nix
: System configuration file containing basic system settings.
Patch hardware-configuration.nix
Add the following content to /mnt/etc/nixos/hardware-configuration.nix
:
Modify the following:
1 | # Adjust the root directory mount options as needed |
Patch configuration.nix
Add the following content to /mnt/etc/nixos/configuration.nix
:
1 | networking.hostName = "<YOUR_HOSTNAME>"; # Set the hostname |
Install NixOS
After adjusting the configuration files, start the installation using the following command:
1 | sudo nixos-install # You will be prompted to set the root password; use the --no-root-passwd option to skip |
After installation, don’t forget to set the password for your account:
1 | nixos-enter --root /mnt -c 'passwd <YOUR_USERNAME>' |
Finally, reboot into the newly installed NixOS system:
1 | sudo reboot |
1 | $ nix-shell -p fastfetch |