How to Install the Operating System NixOS

Introduction

Welcome, brave soul, to the wonderful world of NixOS—the distribution that treats your system like a functional programming project. If you’ve ever dreamed of rolling out reproducible, declarative, atomic upgrades while feeling like a true configuration wizard, you’re in the right place. Buckle up: this tutorial will guide you through every twist and turn of installing NixOS, from flashing the ISO to customizing your first nix-shell. We promise to keep it serious, detailed, and even drop a wink or two along the way.

Prerequisites

  • A computer (real or virtual) with at least 2 GB of RAM and 20 GB of disk space.
  • A reliable Internet connection.
  • A USB stick (≥2 GB) or a virtual-drive tool.
  • Basic familiarity with the command line—no Ph.D. in wizardry required.

Step 1: Download the NixOS ISO

First things first: grab the latest installer ISO from the official site.

  • Visit https://nixos.org/download.html.
  • Choose between Graphical or Minimal images. The graphical one is friendlier the minimal one is lean and mean.
  • Let the download finish. Feel free to stretch, hydrate, or admire your coffee mug’s design.

Step 2: Create a Bootable USB

Convert that shiny ISO into a bootable stick of freedom. On Linux or macOS:

# Identify your USB device (replace sdX accordingly)
sudo lsblk
sudo dd if=/path/to/nixos.iso of=/dev/sdX bs=4M status=progress conv=fsync
    

On Windows, use tools like Rufus or Etcher. Warning: selecting the wrong drive can turn your data into digital confetti, so double-check the device path!

Step 3: Boot and Setup Partitions

Reboot your machine and select the USB under your BIOS/UEFI boot menu. You’ll be welcomed by a Linux terminal prompt. No GUI? No problem—we’re here for serious business.

3.1 Checking Disks

lsblk
    

3.2 Partitioning with cfdisk

sudo cfdisk /dev/sdX
  • Create a 512 MiB EFI partition (type EFI System).
  • Create a swap partition (optional, same size as RAM).
  • Use the rest as root (type Linux filesystem).
writes the changes and exits
    

Tip: If you’re feeling adventurous, use GPT partition table for maximum modernity.

Step 4: Format and Mount Partitions

4.1 Format

sudo mkfs.fat -F32 /dev/sdX1       # EFI
sudo mkswap /dev/sdX2              # Swap
sudo swapon /dev/sdX2
sudo mkfs.ext4 /dev/sdX3           # Root
  

4.2 Mount

sudo mount /dev/sdX3 /mnt
sudo mkdir -p /mnt/boot/efi
sudo mount /dev/sdX1 /mnt/boot/efi
  

All set? Let’s roll into the magic of Nix configurations.

Step 5: Configure NixOS

NixOS lives and breathes /etc/nixos/configuration.nix. Generate a skeleton file:

sudo nixos-generate-config --root /mnt
  

Open /mnt/etc/nixos/configuration.nix with your favorite editor (nano, vim, or emacs if you’re feeling extra).

5.1 Set a Hostname

  networking.hostName = nixos-box # Change to your preference
  

5.2 Configure Users

  users.users.alice = {
    isNormalUser = true
    initialPassword = supersecret # Change later!
  }
  

5.3 Enable Essential Services

  • services.openssh.enable = true – for remote access.
  • networking.firewall.allowedTCPPorts = [ 22 80 443 ] – adjust as needed.
  • services.xserver.enable = true and services.xserver.desktopManager.plasma5.enable = true – for a KDE Plasma desktop.

5.4 Fine-Tune the Kernel

  boot.kernelPackages = pkgs.linuxPackages_latest
  

That’s just the tip of the iceberg. You can declare literally every package your machine needs:

  environment.systemPackages = with pkgs [
    vim htop git curl wget firefox
  ]
  

Step 6: Install NixOS

Ready for the big moment? Sit back as Nix works its functional magic.

sudo nixos-install
  

You’ll be prompted to set a root password. Choose wisely (or use a password manager unless you like typing long strings of random characters daily).

Step 7: Post-install Configuration

  • Reboot:
    sudo reboot
  • Remove the USB stick (lest it be booted again by mistake).
  • Log in as root or your newly created user.
  • Run
    sudo nix-channel --update

    and

    sudo nixos-rebuild switch --upgrade

    regularly to keep your system fresh.

Troubleshooting

Problem: “No network detected!”
Solution: Confirm networking.enable in configuration.nix and run nixos-rebuild switch. Use iwconfig or ifconfig to diagnose.

Problem: GRUB errors at boot.
Solution: Ensure boot.loader.grub.enable = true and correct boot.loader.grub.device. Re-run nixos-install if needed.

Additional Tips and Tricks

  • Declarative dotfiles: Put your .vimrc, .bashrc and friends under /etc/nixos so they’re versioned.
  • Home Manager: Manage user environments declaratively. Learn more at
    Home Manager on GitHub.
  • Rollback: Made a mistake? Reboot and choose an older generation in GRUB. NixOS’s safety net has your back.

Conclusion

Congratulations! You’ve successfully installed NixOS and unlocked a world where every package declaration is deterministic, reproducible, and, dare we say, fun. Remember, NixOS is more than an OS—it’s a mindset. Embrace the power of configuration as code, and before long, you’ll be deploying entire infrastructure stacks from your laptop.

If you’re thirsty for more, the official documentation at
https://nixos.org/manual/ is your trusty companion. Now go forth, configure, upgrade, and roll back with confidence—just don’t forget to reward yourself with a nice cup of tea (or coffee) in true hacker style.

Official Website of NixOS

Download TXT




Leave a Reply

Your email address will not be published. Required fields are marked *