1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 cfg = config.programs.hyprland;
10
11 wayland-lib = import ./lib.nix { inherit lib; };
12in
13{
14 options.programs.hyprland = {
15 enable = lib.mkEnableOption ''
16 Hyprland, the dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
17 You can manually launch Hyprland by executing {command}`Hyprland` on a TTY.
18 A configuration file will be generated in {file}`~/.config/hypr/hyprland.conf`.
19 See <https://wiki.hyprland.org> for more information'';
20
21 package =
22 lib.mkPackageOption pkgs "hyprland" {
23 extraDescription = ''
24 If the package is not overridable with `enableXWayland`, then the module option
25 {option}`xwayland` will have no effect.
26 '';
27 }
28 // {
29 apply =
30 p:
31 wayland-lib.genFinalPackage p {
32 enableXWayland = cfg.xwayland.enable;
33 };
34 };
35
36 portalPackage =
37 lib.mkPackageOption pkgs "xdg-desktop-portal-hyprland" {
38 extraDescription = ''
39 If the package is not overridable with `hyprland`, then the Hyprland package
40 used by the portal may differ from the one set in the module option {option}`package`.
41 '';
42 }
43 // {
44 apply =
45 p:
46 wayland-lib.genFinalPackage p {
47 hyprland = cfg.package;
48 };
49 };
50
51 xwayland.enable = lib.mkEnableOption "XWayland" // {
52 default = true;
53 };
54
55 withUWSM = lib.mkEnableOption null // {
56 description = ''
57 Launch Hyprland with the UWSM (Universal Wayland Session Manager) session manager.
58 This has improved systemd support and is recommended for most users.
59 This automatically starts appropiate targets like `graphical-session.target`,
60 and `wayland-session@Hyprland.target`.
61
62 ::: {.note}
63 Some changes may need to be made to Hyprland configs depending on your setup, see
64 [Hyprland wiki](https://wiki.hyprland.org/Useful-Utilities/Systemd-start/#uwsm).
65 :::
66 '';
67 };
68
69 systemd.setPath.enable = lib.mkEnableOption null // {
70 default = lib.versionOlder cfg.package.version "0.41.2";
71 defaultText = lib.literalExpression ''lib.versionOlder cfg.package.version "0.41.2"'';
72 example = false;
73 description = ''
74 Set environment path of systemd to include the current system's bin directory.
75 This is needed in Hyprland setups, where opening links in applications do not work.
76 Enabled by default for Hyprland versions older than 0.41.2.
77 '';
78 };
79 };
80
81 config = lib.mkIf cfg.enable (
82 lib.mkMerge [
83 {
84 environment.systemPackages = [ cfg.package ];
85
86 xdg.portal = {
87 enable = true;
88 extraPortals = [ cfg.portalPackage ];
89 configPackages = lib.mkDefault [ cfg.package ];
90 };
91
92 systemd = lib.mkIf cfg.systemd.setPath.enable {
93 user.extraConfig = ''
94 DefaultEnvironment="PATH=/run/wrappers/bin:/etc/profiles/per-user/%u/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:$PATH"
95 '';
96 };
97 }
98
99 (lib.mkIf (cfg.withUWSM) {
100 programs.uwsm.enable = true;
101 # Configure UWSM to launch Hyprland from a display manager like SDDM
102 programs.uwsm.waylandCompositors = {
103 hyprland = {
104 prettyName = "Hyprland";
105 comment = "Hyprland compositor managed by UWSM";
106 binPath = "/run/current-system/sw/bin/Hyprland";
107 };
108 };
109 })
110 (lib.mkIf (!cfg.withUWSM) {
111 # To make a vanilla Hyprland session available in DM
112 services.displayManager.sessionPackages = [ cfg.package ];
113 })
114
115 (import ./wayland-session.nix {
116 inherit lib pkgs;
117 enableXWayland = cfg.xwayland.enable;
118 enableWlrPortal = false; # Hyprland has its own portal, wlr is not needed
119 })
120 ]
121 );
122
123 imports = [
124 (lib.mkRemovedOptionModule [
125 "programs"
126 "hyprland"
127 "xwayland"
128 "hidpi"
129 ] "XWayland patches are deprecated. Refer to https://wiki.hyprland.org/Configuring/XWayland")
130 (lib.mkRemovedOptionModule [
131 "programs"
132 "hyprland"
133 "enableNvidiaPatches"
134 ] "Nvidia patches are no longer needed")
135 (lib.mkRemovedOptionModule [
136 "programs"
137 "hyprland"
138 "nvidiaPatches"
139 ] "Nvidia patches are no longer needed")
140 ];
141
142 meta.maintainers = lib.teams.hyprland.members;
143}