2023-04-03 19:39:13 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.wayland.windowManager.hyprland;
|
|
|
|
|
2023-09-21 16:54:35 +02:00
|
|
|
variables = builtins.concatStringsSep " " cfg.systemd.variables;
|
|
|
|
extraCommands = builtins.concatStringsSep " "
|
|
|
|
(map (f: "&& ${f}") cfg.systemd.extraCommands);
|
|
|
|
systemdActivation = ''
|
|
|
|
exec-once = ${pkgs.dbus}/bin/dbus-update-activation-environment --systemd ${variables} ${extraCommands}
|
|
|
|
'';
|
2023-04-03 19:39:13 +02:00
|
|
|
in {
|
|
|
|
meta.maintainers = [ lib.maintainers.fufexan ];
|
|
|
|
|
|
|
|
# A few option removals and renames to aid those migrating from the upstream
|
|
|
|
# module.
|
|
|
|
imports = [
|
|
|
|
(lib.mkRemovedOptionModule # \
|
|
|
|
[ "wayland" "windowManager" "hyprland" "disableAutoreload" ]
|
2023-08-14 09:40:09 +02:00
|
|
|
"Autoreloading now always happens")
|
2023-04-03 19:39:13 +02:00
|
|
|
|
|
|
|
(lib.mkRemovedOptionModule # \
|
|
|
|
[ "wayland" "windowManager" "hyprland" "recommendedEnvironment" ]
|
|
|
|
"Recommended environment variables are now always set")
|
|
|
|
|
2023-08-14 09:40:09 +02:00
|
|
|
(lib.mkRemovedOptionModule # \
|
|
|
|
[ "wayland" "windowManager" "hyprland" "xwayland" "hidpi" ]
|
|
|
|
"HiDPI patches are deprecated. Refer to https://wiki.hyprland.org/Configuring/XWayland")
|
|
|
|
|
2024-04-19 19:25:59 +02:00
|
|
|
(lib.mkRemovedOptionModule # \
|
2023-04-03 19:39:13 +02:00
|
|
|
[ "wayland" "windowManager" "hyprland" "nvidiaPatches" ] # \
|
2024-04-19 19:25:59 +02:00
|
|
|
"Nvidia patches are no longer needed")
|
|
|
|
(lib.mkRemovedOptionModule # \
|
|
|
|
[ "wayland" "windowManager" "hyprland" "enableNvidiaPatches" ] # \
|
|
|
|
"Nvidia patches are no longer needed")
|
2023-09-21 16:54:35 +02:00
|
|
|
|
|
|
|
(lib.mkRenamedOptionModule # \
|
|
|
|
[ "wayland" "windowManager" "hyprland" "systemdIntegration" ] # \
|
|
|
|
[ "wayland" "windowManager" "hyprland" "systemd" "enable" ])
|
2023-04-03 19:39:13 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
options.wayland.windowManager.hyprland = {
|
2024-07-05 01:07:22 +02:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable configuration for Hyprland, a tiling Wayland
|
|
|
|
compositor that doesn't sacrifice on its looks.
|
|
|
|
|
|
|
|
::: {.note}
|
|
|
|
This module configures Hyprland and adds it to your user's {env}`PATH`,
|
|
|
|
but does not make certain system-level changes. NixOS users should
|
|
|
|
enable the NixOS module with {option}`programs.hyprland.enable`, which
|
|
|
|
makes system-level changes such as adding a desktop session entry.
|
|
|
|
:::
|
|
|
|
'';
|
|
|
|
};
|
2023-04-03 19:39:13 +02:00
|
|
|
|
|
|
|
package = lib.mkPackageOption pkgs "hyprland" { };
|
|
|
|
|
|
|
|
finalPackage = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
|
|
|
readOnly = true;
|
2024-04-19 19:25:59 +02:00
|
|
|
default = cfg.package.override { enableXWayland = cfg.xwayland.enable; };
|
2023-04-03 19:39:13 +02:00
|
|
|
defaultText = lib.literalMD
|
|
|
|
"`wayland.windowManager.hyprland.package` with applied configuration";
|
|
|
|
description = ''
|
|
|
|
The Hyprland package after applying configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
plugins = lib.mkOption {
|
|
|
|
type = with lib.types; listOf (either package path);
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
List of Hyprland plugins to use. Can either be packages or
|
|
|
|
absolute plugin paths.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-09-21 16:54:35 +02:00
|
|
|
systemd = {
|
|
|
|
enable = lib.mkEnableOption null // {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable {file}`hyprland-session.target` on
|
|
|
|
hyprland startup. This links to `graphical-session.target`.
|
|
|
|
Some important environment variables will be imported to systemd
|
|
|
|
and D-Bus user environment before reaching the target, including
|
|
|
|
- `DISPLAY`
|
|
|
|
- `HYPRLAND_INSTANCE_SIGNATURE`
|
|
|
|
- `WAYLAND_DISPLAY`
|
|
|
|
- `XDG_CURRENT_DESKTOP`
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
variables = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
default = [
|
|
|
|
"DISPLAY"
|
|
|
|
"HYPRLAND_INSTANCE_SIGNATURE"
|
|
|
|
"WAYLAND_DISPLAY"
|
|
|
|
"XDG_CURRENT_DESKTOP"
|
|
|
|
];
|
2024-04-02 23:39:11 +02:00
|
|
|
example = [ "--all" ];
|
2023-09-21 16:54:35 +02:00
|
|
|
description = ''
|
|
|
|
Environment variables to be imported in the systemd & D-Bus user
|
|
|
|
environment.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraCommands = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
default = [
|
|
|
|
"systemctl --user stop hyprland-session.target"
|
|
|
|
"systemctl --user start hyprland-session.target"
|
|
|
|
];
|
|
|
|
description = "Extra commands to be run after D-Bus activation.";
|
|
|
|
};
|
2024-02-09 18:09:33 +01:00
|
|
|
|
|
|
|
enableXdgAutostart = lib.mkEnableOption ''
|
|
|
|
autostart of applications using
|
|
|
|
{manpage}`systemd-xdg-autostart-generator(8)`'';
|
2023-04-03 19:39:13 +02:00
|
|
|
};
|
|
|
|
|
2023-08-14 09:40:09 +02:00
|
|
|
xwayland.enable = lib.mkEnableOption "XWayland" // { default = true; };
|
2023-04-03 19:39:13 +02:00
|
|
|
|
|
|
|
settings = lib.mkOption {
|
|
|
|
type = with lib.types;
|
|
|
|
let
|
|
|
|
valueType = nullOr (oneOf [
|
|
|
|
bool
|
|
|
|
int
|
|
|
|
float
|
|
|
|
str
|
|
|
|
path
|
|
|
|
(attrsOf valueType)
|
|
|
|
(listOf valueType)
|
|
|
|
]) // {
|
|
|
|
description = "Hyprland configuration value";
|
|
|
|
};
|
|
|
|
in valueType;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
Hyprland configuration written in Nix. Entries with the same key
|
|
|
|
should be written as lists. Variables' and colors' names should be
|
|
|
|
quoted. See <https://wiki.hyprland.org> for more examples.
|
|
|
|
|
|
|
|
::: {.note}
|
|
|
|
Use the [](#opt-wayland.windowManager.hyprland.plugins) option to
|
|
|
|
declare plugins.
|
|
|
|
:::
|
|
|
|
|
|
|
|
'';
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
{
|
|
|
|
decoration = {
|
|
|
|
shadow_offset = "0 5";
|
|
|
|
"col.shadow" = "rgba(00000099)";
|
|
|
|
};
|
|
|
|
|
|
|
|
"$mod" = "SUPER";
|
|
|
|
|
|
|
|
bindm = [
|
|
|
|
# mouse movements
|
|
|
|
"$mod, mouse:272, movewindow"
|
|
|
|
"$mod, mouse:273, resizewindow"
|
|
|
|
"$mod ALT, mouse:272, resizewindow"
|
|
|
|
];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = lib.mkOption {
|
|
|
|
type = lib.types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
# window resize
|
|
|
|
bind = $mod, S, submap, resize
|
|
|
|
|
|
|
|
submap = resize
|
|
|
|
binde = , right, resizeactive, 10 0
|
|
|
|
binde = , left, resizeactive, -10 0
|
|
|
|
binde = , up, resizeactive, 0 -10
|
|
|
|
binde = , down, resizeactive, 0 10
|
|
|
|
bind = , escape, submap, reset
|
|
|
|
submap = reset
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra configuration lines to add to `~/.config/hypr/hyprland.conf`.
|
|
|
|
'';
|
|
|
|
};
|
2023-12-09 13:26:07 +01:00
|
|
|
|
|
|
|
sourceFirst = lib.mkEnableOption ''
|
|
|
|
putting source entries at the top of the configuration
|
|
|
|
'' // {
|
|
|
|
default = true;
|
|
|
|
};
|
2024-04-27 04:32:08 +02:00
|
|
|
|
|
|
|
importantPrefixes = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
default = [ "$" "bezier" "name" ]
|
|
|
|
++ lib.optionals cfg.sourceFirst [ "source" ];
|
|
|
|
example = [ "$" "bezier" ];
|
|
|
|
description = ''
|
|
|
|
List of prefix of attributes to source at the top of the config.
|
|
|
|
'';
|
|
|
|
};
|
2023-04-03 19:39:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "wayland.windowManager.hyprland" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
|
|
|
warnings = let
|
2023-09-21 16:54:35 +02:00
|
|
|
inconsistent = (cfg.systemd.enable || cfg.plugins != [ ])
|
2023-04-03 19:39:13 +02:00
|
|
|
&& cfg.extraConfig == "" && cfg.settings == { };
|
|
|
|
warning =
|
2023-09-21 16:54:35 +02:00
|
|
|
"You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings or hyprland.extraConfig. This is almost certainly a mistake.";
|
2023-04-03 19:39:13 +02:00
|
|
|
in lib.optional inconsistent warning;
|
|
|
|
|
2024-06-09 13:11:01 +02:00
|
|
|
home.packages = lib.concatLists [
|
|
|
|
(lib.optional (cfg.package != null) cfg.finalPackage)
|
|
|
|
(lib.optional (cfg.xwayland.enable) pkgs.xwayland)
|
|
|
|
];
|
2023-04-03 19:39:13 +02:00
|
|
|
|
|
|
|
xdg.configFile."hypr/hyprland.conf" = let
|
2023-09-21 16:54:35 +02:00
|
|
|
shouldGenerate = cfg.systemd.enable || cfg.extraConfig != ""
|
2024-01-21 00:40:55 +01:00
|
|
|
|| cfg.settings != { } || cfg.plugins != [ ];
|
2023-04-03 19:39:13 +02:00
|
|
|
|
2024-01-21 00:40:55 +01:00
|
|
|
pluginsToHyprconf = plugins:
|
2024-04-27 04:32:08 +02:00
|
|
|
lib.hm.generators.toHyprconf {
|
|
|
|
attrs = {
|
|
|
|
plugin = let
|
|
|
|
mkEntry = entry:
|
|
|
|
if lib.types.package.check entry then
|
|
|
|
"${entry}/lib/lib${entry.pname}.so"
|
|
|
|
else
|
|
|
|
entry;
|
|
|
|
in map mkEntry cfg.plugins;
|
|
|
|
};
|
|
|
|
inherit (cfg) importantPrefixes;
|
|
|
|
};
|
2023-04-03 19:39:13 +02:00
|
|
|
in lib.mkIf shouldGenerate {
|
2023-09-21 16:54:35 +02:00
|
|
|
text = lib.optionalString cfg.systemd.enable systemdActivation
|
2024-01-21 00:40:55 +01:00
|
|
|
+ lib.optionalString (cfg.plugins != [ ])
|
|
|
|
(pluginsToHyprconf cfg.plugins)
|
2024-04-27 04:32:08 +02:00
|
|
|
+ lib.optionalString (cfg.settings != { })
|
|
|
|
(lib.hm.generators.toHyprconf {
|
|
|
|
attrs = cfg.settings;
|
|
|
|
inherit (cfg) importantPrefixes;
|
|
|
|
}) + lib.optionalString (cfg.extraConfig != "") cfg.extraConfig;
|
2023-09-21 16:54:35 +02:00
|
|
|
|
2023-04-03 19:39:13 +02:00
|
|
|
onChange = lib.mkIf (cfg.package != null) ''
|
2024-05-24 22:26:52 +02:00
|
|
|
(
|
2024-05-23 02:39:43 +02:00
|
|
|
XDG_RUNTIME_DIR=''${XDG_RUNTIME_DIR:-/run/user/$(id -u)}
|
|
|
|
if [[ -d "/tmp/hypr" || -d "$XDG_RUNTIME_DIR/hypr" ]]; then
|
2024-01-31 17:01:18 +01:00
|
|
|
for i in $(${cfg.finalPackage}/bin/hyprctl instances -j | jq ".[].instance" -r); do
|
2024-02-24 21:04:47 +01:00
|
|
|
${cfg.finalPackage}/bin/hyprctl -i "$i" reload config-only
|
2024-01-31 17:01:18 +01:00
|
|
|
done
|
|
|
|
fi
|
2023-04-03 19:39:13 +02:00
|
|
|
)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-09-21 16:54:35 +02:00
|
|
|
systemd.user.targets.hyprland-session = lib.mkIf cfg.systemd.enable {
|
2023-04-03 19:39:13 +02:00
|
|
|
Unit = {
|
|
|
|
Description = "Hyprland compositor session";
|
|
|
|
Documentation = [ "man:systemd.special(7)" ];
|
|
|
|
BindsTo = [ "graphical-session.target" ];
|
2024-02-09 18:09:33 +01:00
|
|
|
Wants = [ "graphical-session-pre.target" ]
|
|
|
|
++ lib.optional cfg.systemd.enableXdgAutostart
|
|
|
|
"xdg-desktop-autostart.target";
|
2023-04-03 19:39:13 +02:00
|
|
|
After = [ "graphical-session-pre.target" ];
|
2024-02-09 18:09:33 +01:00
|
|
|
Before = lib.mkIf cfg.systemd.enableXdgAutostart
|
|
|
|
[ "xdg-desktop-autostart.target" ];
|
2023-04-03 19:39:13 +02:00
|
|
|
};
|
|
|
|
};
|
2023-10-25 18:13:51 +02:00
|
|
|
|
|
|
|
systemd.user.targets.tray = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Home Manager System Tray";
|
|
|
|
Requires = [ "graphical-session-pre.target" ];
|
|
|
|
};
|
|
|
|
};
|
2023-04-03 19:39:13 +02:00
|
|
|
};
|
|
|
|
}
|