Declaratively manage your Hyprland configuration with Home Manager
If you read my last post about managing your dotfiles using Home-Manager, then you are probably curious about managing more than just some simple ZSH or Git configurations. What if you could use it to generate your Hyprland configuration?
This article covers how to do that. However, you will need NixOS with Flakes enabled and Home Manager installed. If you don’t have NixOS installed with Hyprland, follow this guide:
And this guide if you don’t have Flakes enabled or Home Manager installed:
Now let's get started!
Editing your flake.nix
Unlike some of the other programs that Home Manager can work with natively, Hyprland requires a dedicated flake input. It will look something like this:
# flake.nix
{
inputs = {
# ...
hyprland.url = "github:hyprwm/Hyprland";
};
}
If you go to the GitHub repository for the Hyprland project, you will see in the root directory a flake.nix file of its own. That is what this input is referencing. You can see the same with the other inputs that you provide.
But an input without an output is a bit useless, so let's add it.
# flake.nix
{
inputs = {
# ...
};
outputs = {nixpkgs, home-manager, hyprland, ...}@inputs: {
nixosConfiguration = {
hostName = nixkpkgs.lib.nixosSystem {
modules = [
# ...
hyprland.nixosModules.default
{ programs.hyprland.enable = true; }
home-manager.nixosModules.home-manager
{
# ...
home-manager.extraSpecialArgs = { inherit inputs; };
}
];
};
};
};
}
Ok, so let’s break this down. First, we give the outputs access to the Hyprland input from before. Then we define the NixOS configuration for the user. That's where we set Hyprland as a module and enable it.
Since we have Home Manager defined as a NixOS module, we place the basic configuration for that here. Inside that are the special arguments where we are inheriting the inputs, which contain the Hyprland input. This allows Home Manager to configure Hyprland.
Go ahead and rebuild your flake now. ( sudo nixos-rebuild switch --flake .#
)
Editing home.nix
The final step is adding the Hyprland dotfile configuration to your home.nix file. Since the Hyprland configuration can be lengthy, I highly recommend creating a new folder with a file called default.nix
inside of it. But first, there is one thing you need to do in the root home.nix file.
# home.nix
{ inputs, config, pkgs, ... }:
{
imports = [
inputs.hyprland.homeManagerModules.default
./hypr # points to ./hypr/default.nix
];
}
In the ./hypr/default.nix
file ( remember to use relative paths ), add this:
# default.nix
{ config, inputs, pkgs, ... }:
{
wayland.windowManager.hyprland = {
enable = true;
systemdIntegration = true;
extraConfig = ''
# copy your existing hyprland.conf file here
'';
};
}
In the extraConfig
section, just copy your entire hyprland.conf file and paste it there. The only thing you might have to change if you have it enabled is the blur settings. It will look something like this:
extraConfig = ''
# ...
decortation {
blur {
enable = true
# ...
}
# ...
}
'';
Rebuild your flake again. I recommend restarting Hyprland ( the default key bind for this is SUPER + m
). When you log back in you should hopefully have no errors.
And that’s it! The only downside to this method ( if Home Manager is a NixOS module and not standalone ), is that you will have to rebuild your entire system every time you want to save some changes to the Hyprland settings.
Here is the GitHub Gist for this article
And here are my Dotfiles where you can find how I manage my system.