avatarJosiah Brown

Summary

This text provides a guide on installing a minimal version of NixOS with the Wayland compositor Hyprland and Waybar.

Abstract

The text begins by explaining what NixOS is, a distribution of GNU/Linux that is made from the ground up and not based on Debian or Arch. NixOS is a mix of a few things, including Nix, which is both a language and package manager, and NixOS, an operating system based on Nix. The main appeal of Nix and NixOS is that it is reproducible, declarative, and reliable. The text then provides instructions on choosing an ISO, installing NixOS, and configuring networking, Hyprland, and Waybar. The text also includes additional resources for ricing and Nix-related topics.

Bullet points

  • NixOS is a distribution of GNU/Linux that is made from the ground up and not based on Debian or Arch.
  • Nix is both a language and package manager, and NixOS is an operating system based on Nix.
  • Nix and NixOS are reproducible, declarative, and reliable.
  • Instructions are provided on choosing an ISO, installing NixOS, and configuring networking, Hyprland, and Waybar.
  • Additional resources are provided for ricing and Nix-related topics.

Installing NixOS with Hyprland!

NixOS

In this guide, we will install a minimal version of NixOS with the Wayland compositor Hyprland and Waybar. But first, what is NixOS, what is it used for, and why should we use it?

What is NixOS?

Put simply, NixOS is another distribution of GNU/Linux. However, it is made from the ground up and isn’t based on Debian or Arch like a lot of other distros.

According to their site, NixOS is a mix of a few things. Nix itself is both a language and package manager like apt. And NixOS is an operating system based on Nix.

The main appeal of Nix and NixOS is that it is Reproducible, declarative, and Reliable.

Nix allows you to declaratively create a configuration file that contains everything required to reproduce your system. This includes packages, boot configuration, system & environmental variables. You can even declaratively generate your dotfiles using Home Manager. We won’t be going over Home Manager in this article though.

Since packages and settings are declarative, you have to edit your configuration.nix to permanently install packages.

Nix is a full programming language making it easy for developers to create a config for packages. Because of this, the Nixpkgs repository is one of the largest repositories containing over 80,000 packages. You can find a lot of packages here not in other places.

A potential downside to NixOS is actually one of its strong suites. It does things differently. If you were switching from something like Debian to Arch you could still carry a lot of information you learned over to Arch. But with a declarative structure, a lot of things will work differently and you will have to do your own research to figure a lot out. NixOS is NOT a beginner distribution.

If you don’t want to install NixOS but still want access to its features, you can install the Nix by itself on Linux, MacOS, Docker, and WSL2. If you don’t have WSL2 on your Windows 10/11 computer, then read this post:

Choosing an ISO

On the Nix install page scroll down to the NixOS section. Here you can choose what ISO you want. If haven’t installed a system from scratch before I suggest choosing a live graphical ISO with Gnome or KDE. This post will install Hyprland, which is a window manager so you can choose whichever ISO you want under the graphical section.

When you choose an ISO, make sure you get the right one for the hardware architecture you are using. There is a high likelihood that you are using 64-bit Intel/AMD.

Installing

Requirements:

  • A blank USB stick
  • Wired internet connection (Ethernet or Tethered mobile phone)
  • Belena Etcher (or some other way to flash images to a drive)

Flashing & Booting the graphical interface

After choosing the ISO open up Belena Etcher. It will walk you through the process of flashing an image onto the USB stick. Make sure the USB stick is either empty or contains information you don’t care about. Belena Etcher will wipe all the information in order to install the image.

Now shut down the computer you plan on adding NixOS onto. Plug in the flash drive and then turn on the computer. Immediately after pressing the power button, hold down F10 (which might be different for you) to open up the boot menu.

You should have at least 2 options. One option will be the old operating system and the other one should be labeled “USB”. Using the arrow keys, select “USB”. This will boot into the graphical installation interface.

The graphical interface is relatively straightforward. You can explore it a bit before deciding to fully install the operating system. When you’re ready make your way through the installation GUI. After creating the User you get the option to choose a desktop environment. If you want to use Hyprland then select the “No Desktop” option. This will give you a basic terminal emulator environment post-install.

Continue through the installation process and then click “Install” on the summary page. When the installation is complete remove the USB and boot into your new system.

Configuration

Networking

Assuming you have a laptop and want to someday bring it outside (do linux users go outside?), you probably want the ability to connect to WiFi. This is where the /etc/nixos/configuration.nix file comes in. You will be editing this file a lot.

Open it with:

sudo nano /etc/nixos/configuration.nix

This option will probably be in your configuration file already, but if it isn’t add this somewhere in the file:

networking.networkmanager.enable = true;

Save and exit nano. In the terminal type:

sudo nixos-rebuild switch

This command is what you use to build a new generation based on the configuration file. You will use this command a lot. NixOS will automatically build the file so you don’t have to reboot unless you make a graphical interface change or kernel change.

With network manager enabled you can use nmcli device wifi list to list all the available WiFi networks. To connect to your home network use this command where SSID_or_BSSID is the name of the network and insert_password is the network’s password if it needs one:

nmcli device wifi connect SSID_or_BSSID password insert_password

You can use nmcli device to check if you’re connected to the wifi.

If it’s not already set, add your user account to the network manager so you don’t have to use sudo. You can do that like this:

users.users.YourUsername.extraGroups = [ "networkmanager" ];

# or

users.users.YourUsername = {
  extraGroups = [
    "networkmanager"
  ];
};

Enabling Hyprland

Hyprland is a Wayland compositor. That means it's a window manager for the Wayland protocol, which is a modern replacement for X11. Hyprland is extremely easy to configure and looks great with rounded windows, animations, and border colors (all the essentials for a billion-trillion karma on r/unixporn).

To enable Hyprland, add this to your configuration file:

programs.hyprland = {
  enable = true; 
  xwayland.hidpi = true;
  xwayland.enable = true;
};

# Hint Electon apps to use wayland
environment.sessionVariables = {
  NIXOS_OZONE_WL = "1";
};

If you plan on screen sharing then add this too:

services.dbus.enable = true;
xdg.portal = {
  enable = true;
  wlr.enable = true;
  extraPortals = [
    pkgs.xdg-desktop-portal-gtk
  ];
};

Then add these packages to your system packages:

environment.systemPackages = with pkgs; [
  hyprland
  swww # for wallpapers
  xdg-desktop-portal-gtk
  xdg-desktop-portal-hyprland
  xwayland
];

Adding Waybar

Waybar is the go-to bar for most Wayland users. In most cases all you need to do is add it (`waybar`) to your system packages but there is a bug with Hyprland where waybar won’t be able to display your workspaces.

To fix waybar not displaying Hyprland workspaces, add this to your configuration:

nixpkgs.overlays = [
  (self: super: {
    waybar = super.waybar.overrideAttrs (oldAttrs: {
      mesonFlags = oldAttrs.mesonFlags ++ [ "-Dexperimental=true" ];
    });
  })
];

These packages might fix some of your issues too:

environment.systemPackages = with pkgs; [
  meson
  wayland-protocols
  wayland-utils
  wl-clipboard
  wlroots
];

You also probably want some fonts that contain icons, like nerdfonts.

fonts.fonts = with pkgs; [
  nerdfonts
  meslo-lgs-nf
];

Other Options you might want

Sound

By default, there is no sound enabled on NixOS. You can enable it by adding this to your configuration file:

sound.enable = true;
security.rtkit.enable = true;
services.pipewire = {
  enable = true;
  alsa.enable = true;
  alsa.support32Bit = true;
  pulse.enable = true;
};

Then add pavucontrol (GUI sound control) & pipewire to your system packages.

Other

Since the nixpkgs repository is so large, there are a ton of other packages you might want to add. Here are some options:

environment.systemPackages = with pkgs; [
  # web browsers
  brave
  firefox
  tor
  ungoogled-chromium

  # common utilities
  busybox 
  scdoc
  mpv
  gcc
  
  # notification daemon
  dunst
  libnotify

  # version control
  git 
  
  # music
  spotify

  # terminal emulator
  kitty
  foot
 
  # networking
  networkmanagerapplet # GUI for networkmanager
  
  # editors
  neovim
  vi
  emacs
  vscode

  # app launchers
  rofi-wayland
  wofi
];

After adding the options you want, go ahead and run sudo nixos-rebuild switch to commit the changes. To start Hyprland, you should reboot your computer ( sudo reboot ). After reboot you should have a graphical login screen.

Next Steps

If you made it this far, congrats! The next step I would take from here is editing ~/.config/hypr/hyprland.conf . Read the documentation HERE. If you want waybar, dunst, and a wallpaper to load on startup then you should create a bash script that does this. I just called it start.sh.

#!/usr/bin/env bash

# initialize wallpaper daemon
swww init &
# set wallpaper
swww img ~/path/to/file.png &

# networking
nm-applet --indicator &

waybar &
dunst

Then add this to the end of your hyprland.conf file:

exec-once=bash ~/.config/hypr/start.sh

Pressing SUPER + m will restart hyprland, logging you back out. Once you log back in, you should have those apps loaded.

Additional Resources

Ricing

Nix Related

Thank you for reading until the end. Please consider following the writer and this publication. Visit Stackademic to find out more about how we are democratizing free programming education around the world.

Linux
Servers
Productivity
Nix
System Administration
Recommended from ReadMedium