NixOS Installation Guide: Difference between revisions
imported>Matu3ba add instructions from Til's Guide on youtube |
imported>Matu3ba fix headers |
||
Line 95: | Line 95: | ||
On the minimal ISO, or if you are more familiar with <code>wpa_supplicant</code> then you can also run <code>wpa_passphrase ESSID | sudo tee /etc/wpa_supplicant.conf</code>, then enter your password and <code>systemctl restart wpa_supplicant</code>. | On the minimal ISO, or if you are more familiar with <code>wpa_supplicant</code> then you can also run <code>wpa_passphrase ESSID | sudo tee /etc/wpa_supplicant.conf</code>, then enter your password and <code>systemctl restart wpa_supplicant</code>. | ||
== Partitioning == | |||
To partition the persistent storage run <code>sudo fdisk /dev/diskX</code> and follow instructions for DOS or (U)EFI. | To partition the persistent storage run <code>sudo fdisk /dev/diskX</code> and follow instructions for DOS or (U)EFI. | ||
A very simple example setup is given here. | A very simple example setup is given here. | ||
=== DOS === | |||
* o (dos disk label) | * o (dos disk label) | ||
Line 116: | Line 116: | ||
* w (write) | * w (write) | ||
=== UEFI === | |||
* g (gpt disk label) | * g (gpt disk label) | ||
Line 131: | Line 131: | ||
* w (write) | * w (write) | ||
== Label partitions == | |||
This is useful for having multiple setups and makes paritions easier to handle. | This is useful for having multiple setups and makes paritions easier to handle. | ||
Line 142: | Line 142: | ||
* sudo mount /dev/disk/by-label/NIXBOOT /mnt/boot | * sudo mount /dev/disk/by-label/NIXBOOT /mnt/boot | ||
== Swap file (only simple on uefi) == | |||
* sudo dd if=/dev/zero of=/mnt/.swapfile bs=1024 count=2097152 (2GB size) | * sudo dd if=/dev/zero of=/mnt/.swapfile bs=1024 count=2097152 (2GB size) | ||
* sudo chmod 600 /mnt/.swapfile | * sudo chmod 600 /mnt/.swapfile | ||
Line 148: | Line 148: | ||
* sudo swapon /mnt/.swapfile | * sudo swapon /mnt/.swapfile | ||
== NixOS config == | |||
* sudo nixos-generate-config --root /mnt | * sudo nixos-generate-config --root /mnt | ||
* cd /mnt/etc/nixos/ | * cd /mnt/etc/nixos/ | ||
Line 160: | Line 160: | ||
6. change hardware config to use labels | 6. change hardware config to use labels | ||
== NixOS installation == | |||
* cd /mnt | * cd /mnt |
Revision as of 18:59, 6 April 2022
This guide is a companion guide for the official manual. In addition to describing the steps from the official manual, it provides known good instructions for common use cases. When there is a discrepancy between the manual and this guide, the supported case is the one described in the manual.
Use this guide as a step-by-step guide, choices will be presented, use only the selected section, and continue at the section it tells you to at the end.
Installation target
NixOS can be installed on an increasing variety of hardware:
- regular (Intel or AMD) desktop computers, laptops or physically accessible servers, covered on this page
- SBCs (like the Raspberry Pis) and other ARM boards, see NixOS on ARM
- cloud and remote servers, see NixOS friendly hosters
Installation method
NixOS, as with most Linux-based operating systems, can be installed in different ways.
- The classic way, booting from the installation media. (Described below.)
- Booting the media from an existing Linux installation
Making the installation media
Since NixOS 14.11 the installer ISO is hybrid. This means it is bootable on both CD and USB drives. It also boots on EFI systems, like most modern motherboards and apple systems. The following instructions will assume the standard way of copying the image to a USB drive. When using a CD or DVD, the usual methods to burn to disk should work with the iso.
"Burning" to USB drive
First, download a NixOS ISO image or create a custom ISO. Then plug in a USB stick large enough to accommodate the image. Then follow the platform instructions:
From Linux
- Find the right device with
lsblk
orfdisk -l
. Replace/dev/sdX
with the proper device in the following steps. - Burn with:
cp nixos-xxx.iso /dev/sdX
Writing the disk image with dd if=nixos.iso of=/dev/sdX bs=4M status=progress conv=fdatasync
also works.
From macOS
- Find the right device with
diskutil list
, let's saydiskX
. - Unmount with
diskutil unmountDisk diskX
. - Burn with:
sudo dd if=path_to_nixos.iso of=/dev/diskX
From Windows
- Download USBwriter.
- Start USBwriter.
- Choose the downloaded ISO as 'Source'
- Choose the USB drive as 'Target'
- Click 'Write'
- When USBwriter has finished writing, safely unplug the USB drive.
Alternative installation media instructions
The previous methods are the supported methods of making the USB installation media.
Those methods are also documented, they can allow using the USB drive to boot multiple distributions. This is not supported, your mileage may vary.
Booting the installation media
Since the installation media is hybrid, it will boot both in legacy bios mode and UEFI mode.
Whatever mode is used to boot the installation media, your motherboard or computer's configuration may need to be changed to allow booting from a Optical Disk Drive (for CD/DVD) or an external USB drive.
Legacy bios boot
This is the only boot possible on machines lacking EFI/UEFI.
UEFI boot
The EFI bootloader of the installation media is not signed and is not using a signed shim to boot. This means that Secure Boot will need to be disabled to boot.
Connecting to the internet
The installation will definitely need a working internet connection. It is possible to install without one, but the available set of packages is limited.
Wired
For network interfaces supported by the kernel, DHCP resolution should already have happened once the shell is available.
Tethered (Internet Sharing)
If you can not connect to the internet via cable or wifi, you may use smartphone's tethering capability to share internet. Depending on your smartphones capabilities, only stock kernel drivers may be required which can help providing a working network connection.
Wireless
Network Manager is installed on the graphical ISO, meaning that it is possible to use nmtui
on the command line to connect to a network.
On the minimal ISO, or if you are more familiar with wpa_supplicant
then you can also run wpa_passphrase ESSID | sudo tee /etc/wpa_supplicant.conf
, then enter your password and systemctl restart wpa_supplicant
.
Partitioning
To partition the persistent storage run sudo fdisk /dev/diskX
and follow instructions for DOS or (U)EFI.
A very simple example setup is given here.
DOS
- o (dos disk label)
- n new
- p primary (4 primary in total)
- 1 (partition number [1/4])
- 2048 first sector (alignment for performance)
- +500M last sector (boot sector size)
- rm signature (Y), if ex. => warning of overwriting existing system, could use wipefs
- n
- p
- 2
- default (fill up partition)
- default (fill up partition)
- w (write)
UEFI
- g (gpt disk label)
- n
- 1 (partition number [1/128])
- 2048 first sector
- +500M last sector (boot sector size)
- t
- 1 (EFI System)
- n
- 2
- default (fill up partition)
- default (fill up partition)
- w (write)
Label partitions
This is useful for having multiple setups and makes paritions easier to handle.
- lsblk
- sudo mkfs.fat -F 32 /dev/sdX1
- sudo fatlabel /dev/sdX1 NIXBOOT
- sudo mkfs.ext4 /dev/sdX2 -L NIXROOT
- sudo mount /dev/disk/by-label/NIXROOT /mnt
- sudo mkdir -p /mnt/boot
- sudo mount /dev/disk/by-label/NIXBOOT /mnt/boot
Swap file (only simple on uefi)
- sudo dd if=/dev/zero of=/mnt/.swapfile bs=1024 count=2097152 (2GB size)
- sudo chmod 600 /mnt/.swapfile
- sudo mkswap /mnt/.swapfile
- sudo swapon /mnt/.swapfile
NixOS config
- sudo nixos-generate-config --root /mnt
- cd /mnt/etc/nixos/
- sudo vim configuration.nix
Most essential changes:
1. keyboard layout, ie services.xserver.layout
2. users.users.user
with adding entry initialPassword = "pw123";
3. networking (wifi), see below for fix if it breaks
4. boot.loader.grub.device = "/dev/sda"; #or "nodev" for efi only
5. install editor to edit the configuration
6. change hardware config to use labels
NixOS installation
- cd /mnt
- sudo nixos-install
after installation: Run passwd
to change user password.
if internet broke/breaks, try one of the following:
- nixos-rebuild switch --option substitute false # no downloads
- nixos-rebuild switch --option binary-caches "" # no downloads
- wpa_supplicant flags to connect to wifi
Additional notes for specific hardware
These are collected notes or links for specific hardware issues.
- Blog post how to install NixOS on a Dell 9560
- Brand servers may require extra kernel modules be included into initrd (boot.initrd.extraKernelModules in configuration.nix) For example HP Proliant needs "hpsa" module to see the disk drive.