hyprland-wiki/pages/Nix/Hyprland on Home Manager.md

219 lines
5.3 KiB
Markdown
Raw Normal View History

---
title: Hyprland on Home Manager
---
2022-12-18 14:20:19 +01:00
For a list of available options, check the
[Home Manager options](https://nix-community.github.io/home-manager/options.xhtml#opt-wayland.windowManager.hyprland.enable).
2022-12-18 14:20:19 +01:00
{{< callout >}}
2023-12-14 19:02:45 +01:00
- _(Required) NixOS Module_: enables critical components needed to run Hyprland
properly
- _(Optional) Home-manager module_: lets you declaratively configure Hyprland
{{< /callout >}}
2023-12-14 19:02:45 +01:00
## Installation
{{< tabs items="Home Manager,Flakes,No Flakes (with flake-compat)" >}}
2023-12-14 19:02:45 +01:00
{{< tab "Home Manager" >}}
Home Manager has options for Hyprland without needing to import the Flake
module.
```nix
{
wayland.windowManager.hyprland.enable = true;
}
```
{{< /tab >}}
{{< tab "Flakes" >}}
{{< callout >}}
2023-12-14 19:02:45 +01:00
The flake module is merely an extension to the Home Manager downstream module.
It is mainly used as a staging area for new options, so unless you're a tester
you should use the downstream Home Manager module.
{{< /callout >}}
2023-12-14 19:02:45 +01:00
The following snippet of code tries to show how to bring the Hyprland flake from
the flake input and import it into the module system. Feel free to make any
adjustment for your setup.
Don't forget to replace `user@hostname` with your username and hostname!
2022-12-18 14:20:19 +01:00
```nix
# flake.nix
2023-02-14 14:30:40 +01:00
2022-12-18 14:20:19 +01:00
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
hyprland.url = "github:hyprwm/Hyprland";
};
outputs = {nixpkgs, home-manager, hyprland, ...}: {
homeConfigurations."user@hostname" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
hyprland.homeManagerModules.default
{wayland.windowManager.hyprland.enable = true;}
# ...
];
};
};
2022-12-28 16:31:43 +01:00
}
2022-12-18 14:20:19 +01:00
```
2023-12-14 19:02:45 +01:00
{{< /tab >}}
2022-12-18 14:20:19 +01:00
{{< tab "No flakes (with flake-compat)" >}}
2023-12-14 19:02:45 +01:00
{{< callout >}}
2023-12-14 19:02:45 +01:00
The flake module is merely an extension to the Home Manager downstream module.
It is mainly used as a staging area for new options, so unless you're a tester
you should use the downstream Home Manager module.
{{< /callout >}}
2023-12-14 19:02:45 +01:00
The following snippet of code tries to show how to bring the Hyprland flake from
the flake input and import it into the module system. Feel free to make any
adjustment for your setup.
2022-12-18 14:20:19 +01:00
```nix
# home config
2023-02-14 14:30:40 +01:00
{pkgs, ...}: let
2022-12-18 14:20:19 +01:00
flake-compat = builtins.fetchTarball "https://github.com/edolstra/flake-compat/archive/master.tar.gz";
hyprland = (import flake-compat {
src = builtins.fetchTarball "https://github.com/hyprwm/Hyprland/archive/master.tar.gz";
}).defaultNix;
in {
2023-12-14 19:02:45 +01:00
imports = [hyprland.homeManagerModules.default];
2022-12-18 14:20:19 +01:00
2023-12-14 19:02:45 +01:00
wayland.windowManager.hyprland.enable = true;
2022-12-18 14:20:19 +01:00
}
```
2023-12-14 19:02:45 +01:00
{{< /tab >}}
{{< /tabs >}}
## Usage
2023-12-14 19:02:45 +01:00
Once the module is enabled, you can use it to declaratively configure Hyprland.
Here is an example config, made to work with either the upstream Home Manager
module, or the flake-based Home Manager module.
```nix
# home.nix
2023-12-14 19:02:45 +01:00
{
wayland.windowManager.hyprland.settings = {
"$mod" = "SUPER";
bind =
[
"$mod, F, exec, firefox"
", Print, exec, grimblast copy area"
]
++ (
# workspaces
# binds $mod + [shift +] {1..10} to [move to] workspace {1..10}
builtins.concatLists (builtins.genList (
x: let
ws = let
c = (x + 1) / 10;
in
builtins.toString (x + 1 - (c * 10));
in [
"$mod, ${ws}, workspace, ${toString (x + 1)}"
"$mod SHIFT, ${ws}, movetoworkspace, ${toString (x + 1)}"
]
)
10)
);
};
}
```
## Plugins
2023-12-14 19:02:45 +01:00
Hyprland plugins can be added through the `plugins` option:
```nix
wayland.windowManager.hyprland.plugins = [
inputs.hyprland-plugins.packages.${pkgs.system}.hyprbars
"/absolute/path/to/plugin.so"
];
```
For examples on how to build Hyprland plugins using Nix, see the
[official plugins](https://github.com/hyprwm/hyprland-plugins).
## Fixing problems with themes
If your themes for mouse cursors, icons or windows don't load correctly, try
2023-12-14 19:02:45 +01:00
setting them with `home.pointerCursor` and `gtk.theme`, which enable a bunch of
compatibility options that should make the themes load in all situations.
Example configuration:
2023-12-14 19:02:45 +01:00
```nix
home.pointerCursor = {
gtk.enable = true;
# x11.enable = true;
package = pkgs.bibata-cursors;
name = "Bibata-Modern-Classic";
size = 16;
};
gtk = {
enable = true;
theme = {
package = pkgs.flat-remix-gtk;
name = "Flat-Remix-GTK-Grey-Darkest";
};
iconTheme = {
package = pkgs.gnome.adwaita-icon-theme;
name = "Adwaita";
};
font = {
name = "Sans";
size = 11;
};
2023-12-14 19:02:45 +01:00
};
```
2024-04-04 09:29:00 +02:00
## Programs don't work in systemd services, but do on the terminal
This problem is related to systemd not importing the environment by default. It
2024-04-04 09:29:00 +02:00
will not have knowledge of `PATH`, so it cannot run the commands in the
services. This is the most common with user-configured services such as
`hypridle` or `swayidle`.
To fix it, add to your config:
```nix
wayland.windowManager.hyprland.systemd.variables = ["--all"];
```
This setting will produce the following entry in the Hyprland config:
```ini
exec-once = dbus-update-activation-environment --systemd --all
```
Make sure to use the above command if you do not use the Home Manager module.