Home Server Setup Guide (Part 3): Installing NixOS on Your Old Laptop
Ready to transform your old laptop into a NixOS-powered home server? This step-by-step guide covers everything from installation to troubleshooting, including the roadblocks I faced (and how to avoid them!). Let’s get technical!
- A bootable USB drive (8GB+).
Choose your flavor:
Minimal ISO (Recommended): Lightweight, terminal-only. Perfect for servers.
🔗 Download Minimal ISOGraphical ISO: Includes KDE Plasma for desktop users.
🔗 Download Graphical ISO
Download BalenaEtcher.
Flash the ISO to your USB drive.
Pro Tip: If your USB isn’t detected, try formatting it to FAT32 first.
Insert the NixOS bootable USB into your laptop.
Power on the laptop and enter the boot menu (usually by pressing
F12
,Esc
, orDel
depending on your laptop model).Select the USB drive and boot into the NixOS installer.
ls /sys/firmware/efi
If the directory exists, you’re in UEFI mode (which we’ll proceed with).
If not, you’re in Legacy mode. For Legacy mode, skip the EFI partition steps and adjust accordingly.
lsblk
Look for a device like /dev/sda (your primary drive). If you’re unsure, double-check the size of the disk.
Mistake I Faced : I accidentally wiped the wrong disk because I didn’t verify the disk name. Always double-check!
parted /dev/sda -- mklabel gpt
- This removes all existing partitions, so make sure you have backed up any important data.
EFI System Partition (ESP) for boot (512MB, FAT32)
Root partition (ext4, remaining space except swap)
Swap partition (8GB)
# Create root partition (from 512MB to last 8GB)
parted /dev/sda -- mkpart root ext4 512MB -8GB
# Create swap partition (last 8GB)
parted /dev/sda -- mkpart swap linux-swap -8GB 100%
# Create EFI partition (first 512MB)
parted /dev/sda -- mkpart ESP fat32 1MB 512MB
parted /dev/sda -- set 3 esp on
- Mistake I Faced: I initially created the partitions in the wrong order, which caused boot issues. Always create partitions in this order: root, swap, then EFI.
- Format Root Partition (ext4)
mkfs.ext4 -L nixos /dev/sda1
- Format Swap Partition
mkswap -L swap /dev/sda2
- Format Boot Partition (FAT32)
mkfs.fat -F 32 -n Boot /dev/sda3
- Mistake I Faced: I forgot to label the partitions, which made mounting them later a hassle. Always label your partitions!
- Mount the root partition
mount /dev/disk/by-label/nixos /mnt
- Create and mount the boot partition:
mkdir -p /mnt/boot
mount -o umask=077 /dev/disk/by-label/Boot /mnt/boot
- Enable swap:
swapon /dev/sda2
- Mistake I Faced: I forgot to enable swap, which caused the system to run out of memory during installation. Always enable swap!
- Generate the default NixOS configuration:
nixos-generate-config --root /mnt
- Edit the configuration if needed:
nano /mnt/etc/nixos/configuration.nix
- Run the installation command:
nixos-install
- It will install NixOS based on the generated configuration. During the process, it will prompt you to set a root password:
Setting root password...
New password: ***
Retype new password: ***
- After installation is complete, reboot:
reboot
- If you don’t have an Ethernet port (like me), you’ll need to connect to Wi-Fi via the command line. Here’s how:
ip link
- Look for an interface like wlp1s0 (your Wi-Fi adapter).
- Use iw to scan for Wi-Fi networks:
sudo iw dev wlp1s0 scan | grep SSID
- Generate a wpa_supplicant Configuration:
sudo nano /etc/wpa_supplicant.conf
- Add your Wi-Fi network details:
network={
ssid="Your-WiFi-SSID"
psk="Your-WiFi-Password"
}
sudo wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant.conf
ip link show
Log in as root (since we haven’t created a user yet).
you can create a user and set a password directly in the configuration.nix file. Here’s how:
sudo nano /etc/nixos/configuration.nix
users.users.yourusername = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable sudo access
initialPassword = "yourpassword"; # Set an initial password
};
sudo nixos-rebuild switch
su - yourusername
sudo ls