Hyprland on NixOS

This article describes how to create a workable Hyprland setup on NixOS.

NixOS Configuration

I do not manage my system configuration with Flakes (although I do use them for a whole host of other software) and this article assumes you are also still using the default /etc/nixos/configuration.nix setup.

Copy the following into a file called /etc/nixos/hyprland.nix:

{ config, pkgs, ...}:                                                                
let                                                                                  
in {                                                                                 
  environment.systemPackages = with pkgs; [                                       
    dolphin                                                                          
    dunst                                                                            
    kitty                                                                            
    libnotify                                                                        
    networkmanagerapplet                                                             
    rofi-wayland                                                                     
    swww                                                                             
    waybar   
  ];                                                                                 

  programs.hyprland.enable = true;
  programs.hyprland.xwayland.enable = true;

  environment.sessionVariables = {                                                   
    NIXOS_OZONE_WL = "1";                                                            
  };                                                                                 
                                                                                     
  fonts.fonts = with pkgs; [                                                         
    font-awesome                                                                     
    nerdfonts                                                                        
  ];                                                                                 
                                                                                     
  xdg.portal.enable = true;                                                          
  xdg.portal.extraPortals = with pkgs; [                                             
    xdg-desktop-portal-wlr                                                           
  ];  
}

and then import that into your main /etc/nixos/configuration.nix:

  imports =                                                                          
    [ # Include the results of the hardware scan.                                    
      ./hardware-configuration.nix                                                   
      ./hyprland.nix                                                                 
    ];      

Rebuild your configuration and reboot:

sudo nixos-rebuild switch && shutdown -r now

When you next login be sure to select Hyprland under the cog icon before entering your password.

Amending the Hyprland Configuration

When you first boot into Hyprland it'll look incomplete. We can fix that with a little bit of configuration. You can manage the things below in a variety of ways to make your system fully declarative, but for expediency here we'll just create the files and leave that as an exercise for the reader.

Launch a terminal with Super+Q and create a file ~/.config/hypr/startup.sh with the following contents:

#!/usr/bin/env bash
waybar &
swww init && swww img ~/Pictures/wallpaper.jpg  # amend to suit
nm-applet --indicator &
dunst &

Next open ~/.config/hyper/hyperland.conf and make the following amendments:

autogenerated = 0
exec-once = bash ~/.config/hypr/startup.sh

This will get the basic things you expect of a desktop environment like a status bar, network controls, notifications and wallpaper working.

Conclusion

Give the whole thing another reboot (for luck) and the next time you log in you will have a basic functional desktop environment. There's still some stuff missing that if you're used to distro-provided Gnome or KDE you'll need to add, a lock screen being the most obvious.