NixOS & Tiling WMs: A Perfect Match
Introduction #
I’ve been using NixOS for around 2 years now after migrating from Arch. For most of that time I’ve been using traditional desktop environments (mostly KDE Plasma and GNOME Shell).
Recently, I’ve started to get into using window managers instead of a traditional desktop environment, partly down to me now using NixOS.
Why NixOS? #
One thing that has always kept me from using window managers is that they require you to piece together your system yourself, which is a great selling point, but for me, I was concerned about investing hours into creating my perfect environment and having a bunch of different config files scattered around my system, and a bunch of packages installed to make it work that I would forget all about in time. Then when I inevitably re-install my distro, or move to a new machine, I will have to re-invest that time into creating the perfect configuration again.
I am aware that dotfile managers like stow
exist, I even created my own simple dotfile manager. but these tools have never really done it for me. I think its because you have to actively remember to configure them and add the files to your dotfile manager.
With NixOS, you’re forced to configure your system in a single place (configuration.nix
). This gave me much more confidence to give window managers a try since all of my configuration will be saved in my Nix config, which I keep on Github.
With NixOS, all your tweaks, system packages, configs, fonts, themes, and even user applications can be declared in a single, version controlled location.
This is perfect for:
- Reproducibility: Reinstalling or cloning your setup to a new machine is as simple as cloning your config and running
nixos-rebuild switch
- Atomic Switching: Its easy and safe to tinker with your config or try out a new WM as you can always roll back to a working version.
- Single Configuration: Everything, from installing packages to managing dotfiles, is all in code and uses a single configuration format.
Starting with Hyprland #
I decided that I wanted to go with a Wayland based WM instead of something that runs on Xorg, so my first stop was Hyprland, which is one of the most well known Wayland window managers out there at the moment. Getting started with Hyprland was as simple as adding a few lines to my Nix config:
{
programs.hyprland.enable = true;
programs.hyprlock.enable = true; # Hyprland's screen locker
services.swaync.enable = true; # Notification daemon
}
This setup allowed me to try out Hyprland and create my perfect configuration, safe in the knowledge that all my config is version controlled, in a single location and I’m free to cleanly switch back to my traditional desktop environment if I need to, without leaving any packages installed and left behind. In fact, I did this a few times as I tried to create my perfect Hyprland setup.
Switching to Niri #
Later on, I got curious about Niri, another Wayland WM with a scrolling paradigm, similar to PaperWM and Material Shell which I’ve tried before and quite enjoyed. I was keen to give this a try because of it’s extensive use of touchpad gestures, and an excellent Overview mode.
On a traditional distro, switching window managers often leaves behind unused configuration files or dependencies. But with NixOS, transitioning was clean and no traces of Hyprland were left behind.
I simply swapped out my Hyprland related configuration for the Niri equivalents:
{
programs.niri.enable = true;
programs.swaylock.enable = true; # Screen locker for the Niri setup
services.swaync.enable = true; # Notification daemon
}
Everything related to Hyprland and hyprlock
was removed from my config, ensuring that only Niri, swaylock, and the tools I needed were installed and active. No cruft, no lingering configs. Since my Nix config is version controlled, I could easily switch back to Hyprland if needed.
This modular, declarative approach makes it incredibly easy to experiment. If I ever want to revisit Hyprland (or try another window manager), it’s just a matter of editing my config and running a rebuild. No more orphaned packages, no more “dotfile drift.”
Managing User Configuration with Home Manager #
One detail that really streamlines my setup is Home Manager. Home Manager lets you declare user-specific dotfiles and settings in Nix, right alongside your system configuration. This is incredibly useful when experimenting with different window managers, since you often want to change things like terminal emulator settings, keybindings, or application defaults on a per-environment basis.
For example, here’s how you might enable Niri and configure alacritty as your terminal in your Home Manager config:
{ pkgs, ... }:
{
programs.niri = {
enable = true;
# Additional niri configuration here
};
programs.alacritty.enable = true;
# Configure themes, fonts, etc.
}
With Home Manager, switching window managers doesn’t just swap your system packages—it also updates your user-level config (things like your shell, prompt, launchers, waybar). Just update your Nix and Home Manager configs, run home-manager switch
, and you’re good to go.
Bonus: All these settings are version-controlled, too. If you want to try different configurations for each window manager, you can break them out into separate files and import them conditionally, keeping your setup clean and modular.
Conclusion #
Experimenting with tiling window managers can be quite daunting and time-consuming, especially if you’re used to a full featured desktop environment like GNOME or KDE as you have to piece it together yourself. But with NixOS and Home Manager, I’ve actually had a lot of fun tweaking my system to suit my workflow perfectly. Everything, from the window manager itself and all of the user preferences are housed in my config and version controlled. That lets me experiment, knowing I can always roll back without any leftover files or packages.
If you’re curious about customizing your Linux workflow or have been hesitant to leave the comfort of KDE or GNOME, I highly recommend giving it a try. With NixOS’s declarative configuration, you’re empowered to create, break, and rebuild your perfect desktop environment as many times as you want—cleanly.