1080*80 ad

NixOS Installation with Gnome on VirtualBox

A Step-by-Step Guide to Installing NixOS with GNOME on VirtualBox

NixOS stands out in the crowded world of Linux distributions due to its unique approach to package and configuration management. By using a declarative model, it allows you to define your entire system configuration in a single file, making your setup reproducible, reliable, and easy to roll back. If you’re curious to explore this powerful operating system without affecting your current setup, installing it in a virtual machine is the perfect solution.

This guide will walk you through the complete process of installing NixOS with the popular GNOME desktop environment inside VirtualBox.

Prerequisites

Before we begin, ensure you have the following ready:

  • Oracle VirtualBox: Installed and running on your host machine.
  • NixOS ISO Image: Download the latest stable graphical ISO with GNOME from the official NixOS website.
  • Basic Linux Command-Line Knowledge: Familiarity with commands for navigation and editing text files will be helpful.

Step 1: Create the Virtual Machine in VirtualBox

First, we need to prepare the virtual environment for our NixOS installation.

  1. Open VirtualBox and click “New” to start the new virtual machine wizard.
  2. Name and Operating System: Give your VM a descriptive name like “NixOS GNOME”. Set the Type to “Linux” and the Version to “Linux 2.6 / 3.x / 4.x (64-bit)” or a more specific option if available.
  3. Memory Size: Allocate at least 4 GB (4096 MB) of RAM for a smooth GNOME experience. More is better if your host system allows it.
  4. Hard Disk: Select “Create a virtual hard disk now”. Choose “VDI (VirtualBox Disk Image)” as the type and “Dynamically allocated” for storage efficiency.
  5. Disk Size: A minimum of 32 GB is recommended to accommodate the operating system, applications, and your files.
  6. Finalize VM Settings: Once the VM is created, select it and go to Settings > System > Processor. Allocate at least 2 CPU cores. Then, navigate to Settings > Display and increase the Video Memory to the maximum possible (e.g., 128 MB) and enable 3D Acceleration.
  7. Load the ISO: Go to Settings > Storage. Click on the empty CD icon under the “Controller: IDE” section. On the right-hand panel, click the disc icon and select “Choose a virtual optical disk file…” to load the NixOS ISO you downloaded.

With the virtual machine configured, you’re ready to start the installation.

Step 2: Booting and Disk Partitioning

Start the VM you just created. It will boot from the NixOS ISO into a live environment. The first major task is to partition the virtual hard disk.

  1. Open a terminal from the live environment.
  2. Switch to the root user for administrative privileges:
    bash
    sudo -i
  3. Identify your virtual hard disk. It is typically /dev/sda. You can confirm this with the lsblk command.
  4. We will use fdisk to create three essential partitions: a boot partition, a swap partition, and a root partition.
    bash
    fdisk /dev/sda
  5. Inside fdisk, follow these commands:
    • Press g to create a new empty GPT partition table.
    • Press n to create the first partition for boot. Make it 512M in size.
    • Press t to change the partition type, then enter 1 to select the EFI System type.
    • Press n again for the swap partition. We’ll allocate 4G (or an amount equal to your VM’s RAM).
    • Press t, select partition 2, and enter 19 for Linux Swap.
    • Press n one last time to create the root partition. Use the remaining default space.
    • Finally, press w to write the changes to the disk and exit.

Step 3: Formatting and Mounting the Partitions

With the partitions created, we need to format them with the correct filesystems and mount them.

  1. Format the boot partition:
    bash
    mkfs.fat -F 32 -n boot /dev/sda1
  2. Set up and activate the swap partition:
    bash
    mkswap -L swap /dev/sda2
    swapon /dev/sda2
  3. Format the root partition:
    bash
    mkfs.ext4 -L nixos /dev/sda3
  4. Mount the partitions: The NixOS installer expects the root partition to be mounted at /mnt.
    bash
    mount /dev/disk/by-label/nixos /mnt
    mkdir -p /mnt/boot
    mount /dev/disk/by-label/boot /mnt/boot

Step 4: Generating and Editing the NixOS Configuration

This is the core of the NixOS installation. We will generate a base configuration file and then edit it to define our desired system, including the GNOME desktop.

  1. Generate the configuration files:

    nixos-generate-config --root /mnt
    

    This creates two files in /mnt/etc/nixos/: configuration.nix and hardware-configuration.nix. We only need to edit the first one.

  2. Edit configuration.nix: Use the nano text editor, which is available in the live environment.
    bash
    nano /mnt/etc/nixos/configuration.nix

  3. Inside this file, you need to uncomment or add the following lines to set up our system. The file is well-commented, making it easy to navigate.

    • Enable the GRUB bootloader on an EFI system:

      boot.loader.grub.enable = true;
      boot.loader.grub.device = "nodev"; # For EFI systems
      boot.loader.grub.efiSupport = true;
      
    • Set your hostname:

      networking.hostName = "nixos-vm";
      
    • Enable NetworkManager for easy networking:

      networking.networkmanager.enable = true;
      
    • Set your time zone:

      time.timeZone = "America/New_York"; # Replace with your time zone
      
    • Enable the GNOME Desktop Environment:

      services.xserver.enable = true;
      services.xserver.desktopManager.gnome.enable = true;
      services.xserver.displayManager.gdm.enable = true;
      
    • Enable VirtualBox Guest Additions for better integration (like screen resizing and shared clipboard):

      virtualisation.virtualbox.guest.enable = true;
      
    • Define your user account: Replace "yourusername" with your desired username.

      users.users.yourusername = {
        isNormalUser = true;
        extraGroups = [ "wheel" "networkmanager" ]; # 'wheel' for sudo access
      };
      
    • Install some useful packages (optional):
      nix
      environment.systemPackages = with pkgs; [
      vim
      wget
      git
      firefox
      ];

  4. Save the file by pressing Ctrl + X, then Y, and Enter.

Step 5: The Final Installation

With our configuration defined, the final step is to tell NixOS to build and install the system.

  1. Run the installation command:

    nixos-install
    

    This process will download all the required packages and build your system according to your configuration.nix file. It may take some time depending on your internet connection.

  2. During the installation, you will be prompted to set a password for the root user. Choose a strong password.

  3. After the installation completes successfully, you will be prompted to set a password for the normal user you created (yourusername).

  4. Reboot the system:
    bash
    reboot

Important: Before the VM reboots, be sure to go to the VirtualBox menu under Devices > Optical Drives and remove the NixOS ISO to prevent it from booting into the installer again.

Welcome to NixOS

After rebooting, you will be greeted by the GNOME login screen. Log in with the username and password you created. You now have a fully functional, declaratively configured NixOS system running with GNOME!

To update your system or install new software in the future, you simply edit your /etc/nixos/configuration.nix file and run the command sudo nixos-rebuild switch. This powerful workflow is what makes NixOS a truly modern and resilient operating system.

Source: https://kifarunix.com/install-nixos-with-gnome-desktop-on-virtualbox/

900*80 ad

      1080*80 ad