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!

In Part 2, we discussed why NixOS is the ultimate choice for DIY home servers. Now, it’s time to install it, configure your system. I’ll focus on the **minimal installation** (recommended for servers).

What You’ll Need

  • A bootable USB drive (8GB+).

Step 1: Download the NixOS ISO

Choose your flavor:


Step 2: Create a Bootable USB

Using BalenaEtcher (Cross-Platform)

Pro Tip: If your USB isn’t detected, try formatting it to FAT32 first.


Step 3: Boot & Prepare Partitions

3.1 Boot from USB

  • Insert the NixOS bootable USB into your laptop.

  • Power on the laptop and enter the boot menu (usually by pressing F12, Esc, or Del depending on your laptop model).

  • Select the USB drive and boot into the NixOS installer.


step 4. Verify Boot Mode (UEFI or Legacy)

Check if you’re booted in UEFI mode by running:

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.


step 5. Identify Your Disk

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!


step 6. Delete Existing Partitions

Now, we’ll wipe the disk completely:

parted /dev/sda -- mklabel gpt
  • This removes all existing partitions, so make sure you have backed up any important data.

step 7. Create Partitions

We’ll create:

  • EFI System Partition (ESP) for boot (512MB, FAT32)

  • Root partition (ext4, remaining space except swap)

  • Swap partition (8GB)

Run the following commands:

# 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.

step 8. Format Partitions

Now, format each partition properly.

  • 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!

step 9. Mount Partitions

Now, mount the newly formatted 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!

step 10. Generate Configuration Files

  • Generate the default NixOS configuration:
nixos-generate-config --root /mnt
  • Edit the configuration if needed:
nano /mnt/etc/nixos/configuration.nix

step 11. Install NixOS

  • 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: ***

step 12. Reboot Into Your New NixOS System

  • After installation is complete, reboot:
reboot

step 13. Enabling Networking

  • 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:

Connect to Wi-Fi via Command Line

Find Your Wi-Fi Interface:

ip link
  • Look for an interface like wlp1s0 (your Wi-Fi adapter).

Scan for Available Networks:

  • 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"
}

Connect to Wi-Fi:

sudo wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant.conf

Verify the Connection:

ip link show

step 14. First Boot & Setting Up Your User

  • 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:

Edit the Configuration File:

sudo nano /etc/nixos/configuration.nix

Add User Configuration:

users.users.yourusername = {
  isNormalUser = true;
  extraGroups = [ "wheel" ]; # Enable sudo access
  initialPassword = "yourpassword"; # Set an initial password
};

Apply the Changes:

sudo nixos-rebuild switch

Verify the User:

su - yourusername

Test sudo access:

sudo ls