Skip to main content
  1. Posts/

Choosing a Linux Distribution. Should It Be NixOS & How To Install NixOS?

7 mins· 0 · 0 · ·
Zaney
Software NixOS Choosing a Linux Distro Linux
Zaney
Author
Zaney
I am creating content about Linux & FOSS software. You’ll find me rocking NixOS with Hyprland, probably helping somebody with a question. 😎
Table of Contents

Choosing a Linux distribution is a crucial decision for anyone venturing into the world of open-source operating systems. Among the many options available, NixOS stands out as a unique and innovative choice. Unlike traditional Linux distributions, NixOS offers a fundamentally different approach to package management and system configuration, making it an excellent option for both developers and system administrators. By understanding what sets NixOS apart, you can better appreciate its strengths and decide if it’s the right fit for your needs.

What Is NixOS? #

NixOS is a Linux distribution built around the Nix package manager, a powerful tool that introduces a declarative and functional approach to package management. The hallmark feature of NixOS is its declarative configuration model, which allows users to define their entire system—from installed packages to system services and configurations—in a single configuration file. This model ensures that every aspect of the system is reproducible, making it incredibly easy to replicate the same setup on multiple machines or restore a specific configuration after an upgrade or hardware change. For developers who frequently work across different environments, this capability can save hours of manual setup and troubleshooting.

The Package Manager #

One of the standout features of NixOS is its package repository, which is among the largest in the Linux ecosystem. With over 80,000 packages available, NixOS surpasses the repositories of most mainstream Linux distributions, such as Ubuntu, Fedora, and Arch Linux. This vast selection means that users rarely have to worry about the availability of software, whether it’s a common application like Firefox or a niche library for development. Furthermore, the Nix package manager ensures that each package is built in isolation, eliminating issues caused by conflicting dependencies—a common headache in other distributions. This guarantees a level of stability and predictability that is difficult to achieve elsewhere.

Rollback / Generations System #

Another compelling reason to choose NixOS is its immutability and rollback capabilities. Because NixOS treats the entire system configuration as a single, declarative entity, any changes are applied atomically. This means that you can safely experiment with new configurations or software updates without the fear of breaking your system. If something goes wrong, NixOS allows you to roll back to a previous working state effortlessly. This feature is particularly useful for system administrators managing critical infrastructure, where downtime and configuration errors can have significant consequences.

What Makes NixOS Great? #

NixOS also excels in automation and scalability, making it a popular choice for organizations running large-scale deployments. By leveraging the declarative configuration model, system administrators can easily define and manage consistent environments across hundreds or thousands of machines. This is invaluable in modern DevOps workflows, where reproducibility and consistency are key. Additionally, NixOS integrates seamlessly with containerization technologies like Docker and Kubernetes, further enhancing its utility in cloud-native environments.

For developers, NixOS offers a unique advantage in the form of reproducible development environments. By using Nix to define all the dependencies and tools required for a project, developers can ensure that their code runs identically on any machine. This eliminates the “works on my machine” problem and fosters better collaboration across teams. Whether you’re working on a personal project or contributing to an open-source initiative, NixOS provides the tools to streamline your workflow and reduce the friction associated with setting up and maintaining development environments.

Heard NixOS Can Be Complicated? #

The learning curve associated with NixOS can be steep, particularly for users who are accustomed to traditional Linux distributions. The declarative approach requires a shift in mindset, as does working with the Nix expression language used to define configurations. However, the benefits of mastering NixOS far outweigh the initial challenges. The distribution’s documentation is comprehensive, and an active community is always available to help newcomers. For those willing to invest the time to learn, NixOS offers unparalleled control, stability, and flexibility.

A Complete Guide to Installing NixOS #

Step 1: Preparing for Installation #

  1. Check System Requirements

Before you begin, ensure your hardware meets the following requirements:

  • Processor: x86_64 or ARM64 architecture.
  • RAM: At least 2 GB for basic setups; 4 GB or more is recommended.
  • Storage: Minimum of 10 GB; more is required for larger setups or additional packages.

  1. Download the NixOS ISO

Visit the NixOS download page.

Choose the appropriate ISO image for your system:

  • Graphical ISO: Comes with a desktop environment for easier navigation.
  • Minimal ISO: Recommended for advanced users or server setups.

Download the ISO and verify its checksum to ensure file integrity.

Warning! You definitely want to download either the GNOME or KDE Graphical ISO’s! This will have a simple graphical install that will make the process much more straightforward.
  1. Create a Bootable USB

Use a tool like dd (Linux), Rufus (Windows), or Balena Etcher (cross-platform) to create a bootable USB.

For example, on Linux:

sudo dd if=/path/to/nixos.iso of=/dev/sdX bs=4M status=progress

Replace /path/to/nixos.iso with the downloaded ISO path and /dev/sdX with your USB drive.

  1. Backup Your Data

Installing NixOS involves formatting partitions, which will erase existing data. Backup important files before proceeding.

Step 2: Booting into the NixOS Live Environment #

  1. Insert the bootable USB and restart your system.
  2. Access the BIOS/UEFI menu (commonly by pressing F2, F12, Esc, or Del during boot).
  3. Set the USB drive as the primary boot device.
  4. Save changes and boot into the NixOS live environment.

Once booted, you’ll see a terminal or graphical interface, depending on the ISO chosen.

Step 3: Partitioning the Disk #

Warning! This section and the next is only really relevant if you choose to do a minimal installation.

Identify Your Disk #

Run the following command to list available disks:

lsblk

Partition the Disk #

Replace /dev/sdX with your target disk. Here’s an example partitioning scheme:

  1. Create a GPT partition table:
parted /dev/sdX -- mklabel gpt
  1. Create partitions:
  • EFI System Partition (ESP):
parted /dev/sdX -- mkpart ESP fat32 1MiB 512MiB
parted /dev/sdX -- set 1 boot on
  • Root partition:
parted /dev/sdX -- mkpart primary ext4 512MiB 100%
  1. Format the partitions:
mkfs.fat -F32 /dev/sdX1  # Format the EFI partition
mkfs.ext4 /dev/sdX2      # Format the root partition
  1. Mount the partitions:
mount /dev/sdX2 /mnt
mkdir -p /mnt/boot
mount /dev/sdX1 /mnt/boot

Step 4: Installing NixOS #

Generate the Configuration Files #

Run the following command to generate the default system configuration:

nixos-generate-config --root /mnt

This creates two files:

  • /mnt/etc/nixos/configuration.nix: The main configuration file.
  • /mnt/etc/nixos/hardware-configuration.nix: Auto-detected hardware settings.

Edit Configuration.nix #

Open /mnt/etc/nixos/configuration.nix with your preferred text editor (e.g., nano or vim) to customize the system configuration. Here are some common additions:

  • Set the Timezone:
time.timeZone = "America/New_York";
  • Enable a Desktop Environment (optional): For GNOME:
services.xserver.enable = true;
services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.enable = true;
  • Add Users:
users.users.yourusername = {
  isNormalUser = true;
  extraGroups = [ "wheel" "networkmanager" ];
};
  • Set a Bootloader: For UEFI systems:
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;

Start the Installation #

Execute the following command to install NixOS:

nixos-install

During the installation, you’ll be prompted to set a root password. Once complete, reboot the system:

reboot

Remove the USB drive to boot into your new NixOS installation.

Step 5: Post-Installation Configuration #

Update Your System #

Keep your system up-to-date by running:

sudo nixos-rebuild switch --upgrade

Install Additional Packages #

Add desired packages by editing /etc/nixos/configuration.nix. For example:

environment.systemPackages = with pkgs; [ vim firefox git ];

Apply changes with: #

sudo nixos-rebuild switch

Enable Services #

To enable a service, such as ssh, add the following to configuration.nix:

services.openssh.enable = true;

Rebuild the system: #

sudo nixos-rebuild switch

Conclusion #

In conclusion, NixOS is not just another Linux distribution, it is a paradigm shift in how systems are managed and maintained. Its declarative configuration model, extensive package repository, and robust rollback capabilities make it an attractive choice for developers, system administrators, and anyone seeking a modern approach to Linux. While it may not be the most user-friendly distribution for beginners, the long-term benefits of reproducibility, stability, and scalability make it a standout option in the crowded Linux landscape. If you’re looking for a Linux distribution that prioritizes innovation and reliability, NixOS deserves serious consideration.

Related

Reasons Not to Choose Manjaro Linux: Exploring the Downsides
5 mins· 0 · 0
Zaney
Software Tools Linux Manjaro
Understanding the Linux Operating System: An In-Depth Guide
5 mins· 0 · 0
Zaney
Software Tools Linux Linux Operating System
What is a Linux System Administrator? A Comprehensive Guide
6 mins· 0 · 0
Zaney
Software Tools Linux Linux Operating System Linux System Admin
How to Create a Bootable USB in the Linux Terminal
5 mins· 0 · 0
Zaney
Software Tools How To Linux Terminal
A Complete Introduction to Linux: An Actual Helpful Resource For Beginners
10 mins· 0 · 0
Zaney
Software Tools How To Linux RHEL Intro to Linux Beginner Linux Guide Introduction to Linux
How to Find Your Ubuntu Version
2 mins· 0 · 0
Zaney
Software Tools How To Linux Ubuntu