Table of Contents:
Requirements for this guide:
- LVM disk partitioning for flexibility in storage management.
- LUKS encryption for the entire LVM physical volume for security.
- UEFI boot loader and boot partition.
- Unencrypted boot partition to allow the bootloader to access its files.
- USB stick installation.
- Connecting to the internet using WiFi (specifically WPA) instead of Ethernet.
- Full disk installation only; no dual boot.
Expected Outcome: By following this guide, you will have a secure NixOS system with encrypted storage and LVM management, tailored to your specific hardware and preferences.
Important: All commands should be executed as the root user. To gain root access, use:
sudo -iNote: For the most part, installing NixOS is straightforward if you follow this guide. However, a basic understanding of the Nix language is essential. NixOS is deeply integrated with Nix, and you'll need to learn it to create your own configuration or modify an existing one to suit your preferences.
I won’t be covering Nix language fundamentals in this guide. If you have a basic understanding, my example configuration file should be clear and helpful. Learning the basics of Nix is not difficult—it’s quite accessible and easy to grasp. For an introduction, you can refer to the Nix Language Tutorial.
-
Download the 64-bit minimal install CD from the NixOS downloads page.
-
Verify the ISO Integrity
-
Download the SHA256 checksum file from the same page.
-
Place both the ISO and checksum file in the same folder.
-
Run:
sha256sum -c <checksum-file>
-
Ensure the output indicates that the ISO file is
OK. If the verification fails, redownload the ISO and checksum files and repeat the verification process.
-
-
Create a Bootable USB Stick
-
Identify your USB stick:
lsblk
-
Copy the ISO to the USB stick (replace
$DISKwith your USB stick):sudo dd if=<ISO_FILE> of=$DISK bs=1M status=progress
Note: This command will erase all data on the USB stick. Replace
<ISO_FILE>with the name of your ISO file.
-
Some UEFI system settings need to be adjusted for NixOS installation. To find the exact steps for your machine, do a quick web search for your model. For example, on my HP, you press F12 at boot to access the UEFI menu.
Once in the menu:
- Ensure Safe Boot is Disabled.
- Ensure Fast Boot is Disabled.
- Ensure UEFI Mode is Enabled.
- Ensure Boot from USB is Enabled.
Note: I will be using colemak-dh. You can choose other layouts, like fr or de.
The US layout is chosen by default.
sudo loadkeys mod-dh-ansi-usFor other layouts like French or German:
- French:
sudo loadkeys fr - German:
sudo loadkeys de
- Run
nmtuito connect to wifi using a nice tui:
previosly you had to use wpa_supplicant and connect to wifi manually but it is no longer necessary
Tip: For a shorter, more automatic install, use disko. You declare your partitions once and reuse that configuration every time. The entire process becomes two commands:
sudo disko --mode destroy,format,mount /path/to/disko-config.nix sudo nixos-installThat said, the manual
partedsteps below are recommended for your first install. They teach you what happens under the hood, and the workflow will feel familiar if you are coming from an imperative distro like Arch or Gentoo. also Flakes are not recommended for a first install, but they can be a good addition later if you need them.
Warning: Partitioning will erase all data on the disk. Ensure you have backed up any important data before proceeding.
-
Start
partedin interactive mode:parted /dev/nvme0n1
Replace
/dev/nvme0n1with your actual disk identifier if different. -
Create a new GPT partition table:
(parted) mklabel gpt
This command sets up the disk to use the GPT partitioning scheme, which is necessary for UEFI systems.
-
Create the partitions:
-
Create the EFI System Partition (ESP) (1 MiB to 1 GiB):
(parted) mkpart ESP fat32 1MiB 1GiB (parted) set 1 esp onThis sets up a 1 GiB partition formatted as FAT32 for the EFI system. It’s required for UEFI booting.
-
Create the LUKS encrypted partition (1 GiB to end - 1 MiB):
(parted) mkpart LUKS 1GiB -1MiB
This creates the remaining space on the disk for LUKS encryption.
-
-
Print the partition table to verify:
(parted) print
-
Quit
parted:(parted) quit
Format the ESP partition (1 MiB to 1 GiB) as FAT32:
mkfs.fat -F32 -n ESP /dev/nvme0n1p1Initialize the LUKS encrypted partition (1 GiB to end - 1 MiB):
cryptsetup luksFormat /dev/nvme0n1p2Open the LUKS partition:
cryptsetup open /dev/nvme0n1p2 luksCryptedCreate LVM physical volume on the decrypted partition:
pvcreate /dev/mapper/luksCryptedCreate an LVM volume group (e.g., vg0):
vgcreate vg0 /dev/mapper/luksCryptedCreate logical volumes in the following order:
-
Create root volume (50 GiB, adjust based on your requirements):
lvcreate -L 50G -n nixos-root vg0
-
Create home volume (80 GiB, adjust based on your requirements):
lvcreate -L 80G -n nixos-home vg0
-
Create swap volume (20 GiB, adjust based on your requirements; should be at least the size of your RAM if you intend to use hibernation):
lvcreate -L 20G -n nixos-swap vg0
Format logical volumes:
-
Format root volume as ext4:
mkfs.ext4 -L nixos-root /dev/vg0/nixos-root
-
Format home volume as ext4:
mkfs.ext4 -L nixos-home /dev/vg0/nixos-home
-
Format swap volume:
mkswap -L nixos-swap /dev/vg0/nixos-swap
Mount Root Partition:
mount /dev/vg0/nixos-root /mntCreate Necessary Directories on the Root Filesystem:
mkdir /mnt/boot /mnt/homeMount Boot Partition:
mount /dev/nvme0n1p1 /mnt/bootMount Home Partition (if separate):
mount /dev/vg0/nixos-home /mnt/homeEnable Swap:
swapon /dev/vg0/nixos-swap-
Generate the NixOS configuration:
nixos-generate-config --root /mnt
-
Optionally, Download Your Configuration File:
If you don’t have your own configuration file, you can download mine for reference:
curl -o /mnt/etc/nixos/configuration.nix https://raw.githubusercontent.com/aliknis/Nixos-Installation-Guide/main/configuration.nix
Note: This file is customized for my setup. Common changes you might need to make include:
- Updating Partition UUIDs or Paths
- Activating or Deactivating Services
- Installing or Removing Applications
- Configuring Desktop Environment (if needed)
For creating your own configuration, follow these steps:
- Learn the Basics: Begin with the Nix Language Tutorial to understand the fundamentals of Nix.
- Consult the Manual: Read the relevant sections of the NixOS Official Manual for information specific to your setup.
- Refer to My Configuration File: You can view my configuration file.
Further Learning:
After you’ve settled in with NixOS and feel comfortable with the basics, consider exploring the Nix Pills series. These bite-sized tutorials can help you gradually deepen your understanding of Nix concepts. Don’t worry about tackling them right away—they’ll be there when you’re ready to learn more advanced topics.
Remember: Mastering NixOS is a journey. Take your time to understand each concept thoroughly before moving on to more advanced topics.
-
Change to the configuration directory and edit the configuration file using
vimor nano or whatever your poison might be:cd /mnt/etc/nixos vim configuration.nixMake necessary changes to match your setup.
-
Install NixOS:
nixos-install
-
Reboot the system:
reboot