refactor(nixos): migrate Hyprland to Lua

This commit is contained in:
2026-10-08 19:22:04 -04:00
parent 4908c4751f
commit ff376264ee
9 changed files with 295 additions and 123 deletions

View File

@@ -49,8 +49,19 @@
modules.desktop.apps.vencord.enable = true; modules.desktop.apps.vencord.enable = true;
home-manager.users.${config.user.name}.wayland.windowManager.hyprland.settings.monitor = [ home-manager.users.${config.user.name}.wayland.windowManager.hyprland.settings.monitor = [
"HDMI-A-1,1920x1080@120,0x0,1,transform,3" {
"DP-3,2560x1440@239.96,1080x0,1" output = "DP-3";
mode = "2560x1440@239.96";
position = "1080x0";
scale = 1;
}
{
output = "HDMI-A-1";
mode = "1920x1080@120";
position = "0x0";
scale = 1;
transform = 3;
}
]; ];
} }

View File

@@ -8,22 +8,31 @@
let let
cfg = config.modules.desktop.session.hyprland; # NOLINT(let_order) cfg = config.modules.desktop.session.hyprland; # NOLINT(let_order)
cursor = config.stylix.cursor; cursor = config.stylix.cursor;
mkBind = key: dispatcher: options: {
_args = [
(lua key)
dispatcher
]
++ lib.optional (options != { }) options;
};
lua = lib.generators.mkLuaInline;
# Numbered-workspace switch and move for 1..9, the operator's i3 muscle memory. # Numbered-workspace switch and move for 1..9, the operator's i3 muscle memory.
workspaceBinds = lib.concatMap (n: [ workspaceBinds = lib.concatMap (n: [
"$mod, ${toString n}, workspace, ${toString n}" (mkBind ''mod .. " + ${toString n}"'' (lua ''hl.dsp.focus({ workspace = "${toString n}" })'') { })
"$mod SHIFT, ${toString n}, movetoworkspace, ${toString n}" (mkBind ''mod .. " + SHIFT + ${toString n}"''
(lua ''hl.dsp.window.move({ workspace = "${toString n}", follow = false })'')
{ }
)
]) (lib.range 1 9); ]) (lib.range 1 9);
user = config.user.name;
# Flip the tiling strategy between the two built-in layouts, since neither a # Flip the tiling strategy between the two built-in layouts, since neither a
# dispatcher nor a keyword toggles it on its own. # dispatcher nor a keyword toggles it on its own.
toggleLayout = pkgs.writeShellScript "hypr-toggle-layout" '' toggleLayout = pkgs.writeShellScript "hypr-toggle-layout" ''
if [ "$(hyprctl getoption -j general:layout | ${pkgs.jq}/bin/jq -r .str)" = dwindle ]; then if [ "$(${config.programs.hyprland.package}/bin/hyprctl getoption -j general:layout | ${pkgs.jq}/bin/jq -r .str)" = dwindle ]; then
hyprctl keyword general:layout master ${config.programs.hyprland.package}/bin/hyprctl keyword general:layout master
else else
hyprctl keyword general:layout dwindle ${config.programs.hyprland.package}/bin/hyprctl keyword general:layout dwindle
fi fi
''; '';
in in
@@ -44,7 +53,7 @@ in
withUWSM = true; withUWSM = true;
}; };
home-manager.users.${user}.wayland.windowManager.hyprland = { home-manager.users.${config.user.name}.wayland.windowManager.hyprland = {
enable = true; enable = true;
# One package drives the whole session, so there is never a version split. # One package drives the whole session, so there is never a version split.
@@ -56,134 +65,237 @@ in
# uwsm owns the systemd graphical-session targets. # uwsm owns the systemd graphical-session targets.
systemd.enable = false; systemd.enable = false;
# Write the native hyprlang hyprland.conf, whose variable and bind syntax configType = "lua";
# the settings below are expressed in.
configType = "hyprlang";
settings = { settings = {
"$mod" = "SUPER"; mod = {
"$terminal" = "ghostty"; _var = "SUPER";
};
terminal = {
_var = "ghostty";
};
# Session variables handed to the compositor directly. # Session variables handed to the compositor directly.
# UWSM launches the session without the shell profile that would carry # UWSM launches the session without the shell profile that would carry
# them, so a variable the compositor or its children must see is set # them, so a variable the compositor or its children must see is set
# here rather than through home-manager's sessionVariables. # here rather than through home-manager's sessionVariables.
env = [ env = [
# Chromium and Electron apps read this to select native Wayland; {
# nixpkgs wrappers (Obsidian's included) gate their Wayland flags on _args = [
# it, so without it they run under XWayland and blur at this DPI. "NIXOS_OZONE_WL"
"NIXOS_OZONE_WL,1" "1"
];
}
] ]
# Bibata ships XCursor only. # Bibata ships XCursor only.
# The hyprcursor variables name the same theme, which Hyprland # The hyprcursor variables name the same theme, which Hyprland
# resolves through its XCursor fallback. # resolves through its XCursor fallback.
++ lib.optionals (cursor != null) [ ++ lib.optionals (cursor != null) [
"XCURSOR_THEME,${cursor.name}" {
"XCURSOR_SIZE,${toString cursor.size}" _args = [
"HYPRCURSOR_THEME,${cursor.name}" "XCURSOR_THEME"
"HYPRCURSOR_SIZE,${toString cursor.size}" cursor.name
];
}
{
_args = [
"XCURSOR_SIZE"
(toString cursor.size)
];
}
{
_args = [
"HYPRCURSOR_THEME"
cursor.name
];
}
{
_args = [
"HYPRCURSOR_SIZE"
(toString cursor.size)
];
}
]; ];
input = { config = {
kb_layout = "us"; input = {
# Caps is a second Escape. kb_layout = "us";
# Shift+Caps still toggles a real CapsLock. # Caps is a second Escape.
kb_options = "caps:escape_shifted_capslock"; # Shift+Caps still toggles a real CapsLock.
# Snappy key repeat. kb_options = "caps:escape_shifted_capslock";
repeat_delay = 250; # Snappy key repeat.
repeat_rate = 45; repeat_delay = 250;
accel_profile = "flat"; repeat_rate = 45;
touchpad = { accel_profile = "flat";
natural_scroll = true; touchpad = {
tap-to-click = true; natural_scroll = true;
disable_while_typing = true; tap_to_click = true;
disable_while_typing = true;
};
};
general = {
gaps_in = 4;
gaps_out = 8;
border_size = 2;
layout = "dwindle";
};
decoration = {
rounding = 6;
blur.enabled = cfg.blur;
};
# XWayland clients render at the panel's native resolution instead of
# being raster-scaled by the compositor at the fractional monitor scale.
xwayland.force_zero_scaling = true;
animations.enabled = true;
dwindle = {
preserve_split = true;
}; };
}; };
general = { curve = {
gaps_in = 4; _args = [
gaps_out = 8; "ease"
border_size = 2; {
layout = "dwindle"; type = "bezier";
}; points = [
[
decoration = { 0.25
rounding = 6; 0.1
blur.enabled = cfg.blur; ]
}; [
0.25
# XWayland clients render at the panel's native resolution instead of 1.0
# being raster-scaled by the compositor at the fractional monitor scale. ]
xwayland.force_zero_scaling = true; ];
}
animations = {
enabled = true;
bezier = [ "ease, 0.25, 0.1, 0.25, 1.0" ];
# Durations are in centiseconds.
# Short values keep the motion subtle.
animation = [
"windows, 1, 3, ease"
"fade, 1, 3, ease"
# Layer surfaces like the launcher fade in a touch quicker than windows.
"layersIn, 1, 2, ease"
"fadeLayersIn, 1, 2, ease"
"workspaces, 1, 3, ease"
"border, 1, 3, ease"
]; ];
}; };
dwindle = { # Durations are in centiseconds.
preserve_split = true; # Short values keep the motion subtle.
}; animation = [
{
leaf = "windows";
enabled = true;
speed = 3;
bezier = "ease";
}
{
leaf = "fade";
enabled = true;
speed = 3;
bezier = "ease";
}
# Layer surfaces like the launcher fade in a touch quicker than windows.
{
leaf = "layersIn";
enabled = true;
speed = 2;
bezier = "ease";
}
{
leaf = "fadeLayersIn";
enabled = true;
speed = 2;
bezier = "ease";
}
{
leaf = "workspaces";
enabled = true;
speed = 3;
bezier = "ease";
}
{
leaf = "border";
enabled = true;
speed = 3;
bezier = "ease";
}
];
bind = [ bind = [
"$mod, Return, exec, $terminal" (mkBind ''mod .. " + RETURN"'' (lua "hl.dsp.exec_cmd(terminal)") { })
# Move focus. # Move focus.
"$mod, H, movefocus, l" (mkBind ''mod .. " + H"'' (lua ''hl.dsp.focus({ direction = "left" })'') { })
"$mod, J, movefocus, d" (mkBind ''mod .. " + J"'' (lua ''hl.dsp.focus({ direction = "down" })'') { })
"$mod, K, movefocus, u" (mkBind ''mod .. " + K"'' (lua ''hl.dsp.focus({ direction = "up" })'') { })
"$mod, L, movefocus, r" (mkBind ''mod .. " + L"'' (lua ''hl.dsp.focus({ direction = "right" })'') { })
# Move the window within the layout. # Move the window within the layout.
"$mod SHIFT, H, movewindow, l" (mkBind ''mod .. " + SHIFT + H"'' (lua ''hl.dsp.window.move({ direction = "l" })'') { })
"$mod SHIFT, J, movewindow, d" (mkBind ''mod .. " + SHIFT + J"'' (lua ''hl.dsp.window.move({ direction = "d" })'') { })
"$mod SHIFT, K, movewindow, u" (mkBind ''mod .. " + SHIFT + K"'' (lua ''hl.dsp.window.move({ direction = "u" })'') { })
"$mod SHIFT, L, movewindow, r" (mkBind ''mod .. " + SHIFT + L"'' (lua ''hl.dsp.window.move({ direction = "r" })'') { })
# Resize the active window. # Resize the active window.
"$mod ALT, H, resizeactive, -40 0" (mkBind ''mod .. " + ALT + H"'' (lua "hl.dsp.window.resize({ x = -40, y = 0, relative = true })")
"$mod ALT, J, resizeactive, 0 40" { }
"$mod ALT, K, resizeactive, 0 -40" )
"$mod ALT, L, resizeactive, 40 0" (mkBind ''mod .. " + ALT + J"'' (lua "hl.dsp.window.resize({ x = 0, y = 40, relative = true })")
{ }
)
(mkBind ''mod .. " + ALT + K"'' (lua "hl.dsp.window.resize({ x = 0, y = -40, relative = true })")
{ }
)
(mkBind ''mod .. " + ALT + L"'' (lua "hl.dsp.window.resize({ x = 40, y = 0, relative = true })")
{ }
)
"$mod, Space, togglefloating," (mkBind ''mod .. " + SPACE"'' (lua "hl.dsp.window.float()") { })
"$mod, F, fullscreen," (mkBind ''mod .. " + F"'' (lua "hl.dsp.window.fullscreen()") { })
# togglesplit is a dwindle layout message, reached through layoutmsg. # togglesplit is a dwindle layout message, reached through layoutmsg.
"$mod, T, layoutmsg, togglesplit" (mkBind ''mod .. " + T"'' (lua ''hl.dsp.layout("togglesplit")'') { })
"$mod SHIFT, T, exec, ${toggleLayout}" (mkBind ''mod .. " + SHIFT + T"'' (lua "hl.dsp.exec_cmd(${builtins.toJSON toggleLayout})") { })
"$mod SHIFT, Q, killactive," (mkBind ''mod .. " + SHIFT + Q"'' (lua "hl.dsp.window.close()") { })
"$mod CTRL, Q, forcekillactive," (mkBind ''mod .. " + CTRL + Q"'' (lua "hl.dsp.window.kill()") { })
] ]
++ workspaceBinds; ++ workspaceBinds
# Volume and brightness keys repeat while held, each raising a popup # Volume and brightness keys repeat while held, each raising a popup
# through the OSD client. # through the OSD client.
# Volume is capped at 100 percent. # Volume is capped at 100 percent.
# The client floors brightness so a full hold cannot black the screen out. # The client floors brightness so a full hold cannot black the screen out.
binde = [ ++ [
", XF86AudioRaiseVolume, exec, ${pkgs.swayosd}/bin/swayosd-client --output-volume raise --max-volume 100" (mkBind (builtins.toJSON "XF86AudioRaiseVolume")
", XF86AudioLowerVolume, exec, ${pkgs.swayosd}/bin/swayosd-client --output-volume lower" (lua "hl.dsp.exec_cmd(${builtins.toJSON "${pkgs.swayosd}/bin/swayosd-client --output-volume raise --max-volume 100"})")
", XF86MonBrightnessUp, exec, ${pkgs.swayosd}/bin/swayosd-client --brightness raise" { repeating = true; }
", XF86MonBrightnessDown, exec, ${pkgs.swayosd}/bin/swayosd-client --brightness lower" )
]; (mkBind (builtins.toJSON "XF86AudioLowerVolume")
(lua "hl.dsp.exec_cmd(${builtins.toJSON "${pkgs.swayosd}/bin/swayosd-client --output-volume lower"})")
{ repeating = true; }
)
(mkBind (builtins.toJSON "XF86MonBrightnessUp")
(lua "hl.dsp.exec_cmd(${builtins.toJSON "${pkgs.swayosd}/bin/swayosd-client --brightness raise"})")
{ repeating = true; }
)
(mkBind (builtins.toJSON "XF86MonBrightnessDown")
(lua "hl.dsp.exec_cmd(${builtins.toJSON "${pkgs.swayosd}/bin/swayosd-client --brightness lower"})")
{ repeating = true; }
)
]
# Mute and media transport still fire while the session is locked. # Mute and media transport still fire while the session is locked.
bindl = [ ++ [
", XF86AudioMute, exec, ${pkgs.swayosd}/bin/swayosd-client --output-volume mute-toggle" (mkBind (builtins.toJSON "XF86AudioMute")
", XF86AudioPlay, exec, ${pkgs.playerctl}/bin/playerctl play-pause" (lua "hl.dsp.exec_cmd(${builtins.toJSON "${pkgs.swayosd}/bin/swayosd-client --output-volume mute-toggle"})")
", XF86AudioNext, exec, ${pkgs.playerctl}/bin/playerctl next" { locked = true; }
", XF86AudioPrev, exec, ${pkgs.playerctl}/bin/playerctl previous" )
(mkBind (builtins.toJSON "XF86AudioPlay")
(lua "hl.dsp.exec_cmd(${builtins.toJSON "${pkgs.playerctl}/bin/playerctl play-pause"})")
{ locked = true; }
)
(mkBind (builtins.toJSON "XF86AudioNext")
(lua "hl.dsp.exec_cmd(${builtins.toJSON "${pkgs.playerctl}/bin/playerctl next"})")
{ locked = true; }
)
(mkBind (builtins.toJSON "XF86AudioPrev")
(lua "hl.dsp.exec_cmd(${builtins.toJSON "${pkgs.playerctl}/bin/playerctl previous"})")
{ locked = true; }
)
]; ];
}; };
}; };

View File

@@ -86,8 +86,18 @@ in
# The guard drops the keypress when a locker is already up, so a second # The guard drops the keypress when a locker is already up, so a second
# hyprlock never stacks over the first. # hyprlock never stacks over the first.
wayland.windowManager.hyprland.settings.bind = [ wayland.windowManager.hyprland.settings.bind = [
"$mod, X, exec, ${pkgs.procps}/bin/pidof hyprlock || ${hyprlock}" {
"$mod CTRL, X, exec, ${idleLockToggle}" _args = [
(lib.generators.mkLuaInline ''mod .. " + X"'')
(lib.generators.mkLuaInline "hl.dsp.exec_cmd(${builtins.toJSON "${pkgs.procps}/bin/pidof hyprlock || ${hyprlock}"})")
];
}
{
_args = [
(lib.generators.mkLuaInline ''mod .. " + CTRL + X"'')
(lib.generators.mkLuaInline "hl.dsp.exec_cmd(${builtins.toJSON idleLockToggle})")
];
}
]; ];
}; };
}; };

View File

@@ -6,6 +6,10 @@
}: }:
# Text login: greetd running the tuigreet greeter, which starts the session # Text login: greetd running the tuigreet greeter, which starts the session
# through the universal Wayland session manager. # through the universal Wayland session manager.
let
hyprlandConfig =
config.home-manager.users.${config.user.name}.xdg.configFile."hypr/hyprland.lua".source;
in
{ {
options.modules.desktop.session.login.enable = options.modules.desktop.session.login.enable =
lib.mkEnableOption "greetd with the tuigreet text greeter"; lib.mkEnableOption "greetd with the tuigreet text greeter";
@@ -15,7 +19,7 @@
enable = true; enable = true;
settings.default_session.command = settings.default_session.command =
"${lib.getExe pkgs.tuigreet} --time --remember " "${lib.getExe pkgs.tuigreet} --time --remember "
+ "--cmd 'uwsm start -e -D Hyprland hyprland.desktop'"; + "--cmd 'uwsm start -e -D Hyprland ${config.programs.hyprland.package}/bin/Hyprland --config ${hyprlandConfig}'";
}; };
}; };
} }

View File

@@ -34,9 +34,13 @@ in
# Recall the last notification from history, keyboard-only like the rest # Recall the last notification from history, keyboard-only like the rest
# of the session. # of the session.
# $mod is defined by the compositor config these binds share.
wayland.windowManager.hyprland.settings.bind = [ wayland.windowManager.hyprland.settings.bind = [
"$mod, N, exec, ${makoctl} restore" {
_args = [
(lib.generators.mkLuaInline ''mod .. " + N"'')
(lib.generators.mkLuaInline "hl.dsp.exec_cmd(${builtins.toJSON "${makoctl} restore"})")
];
}
]; ];
}; };
}; };

View File

@@ -6,6 +6,7 @@
}: }:
# rofi as the desktop launcher and dmenu-style menu frontend. # rofi as the desktop launcher and dmenu-style menu frontend.
let let
lua = lib.generators.mkLuaInline;
user = config.user.name; user = config.user.name;
# A session menu built on the same themed rofi, so the power actions look # A session menu built on the same themed rofi, so the power actions look
@@ -41,10 +42,19 @@ in
}; };
# The launcher and the session menu, kept next to the tool they drive. # The launcher and the session menu, kept next to the tool they drive.
# $mod is defined by the compositor config these binds share.
wayland.windowManager.hyprland.settings.bind = [ wayland.windowManager.hyprland.settings.bind = [
"$mod, R, exec, ${pkgs.rofi}/bin/rofi -show drun" {
"$mod SHIFT, X, exec, ${powerMenu}" _args = [
(lua ''mod .. " + R"'')
(lua "hl.dsp.exec_cmd(${builtins.toJSON "${pkgs.rofi}/bin/rofi -show drun"})")
];
}
{
_args = [
(lua ''mod .. " + SHIFT + X"'')
(lua "hl.dsp.exec_cmd(${builtins.toJSON powerMenu})")
];
}
]; ];
}; };
}; };

View File

@@ -39,9 +39,13 @@ in
# session so uwsm starts and stops them with it. # session so uwsm starts and stops them with it.
services.cliphist.enable = true; services.cliphist.enable = true;
# $mod is defined by the compositor config these binds share.
wayland.windowManager.hyprland.settings.bind = [ wayland.windowManager.hyprland.settings.bind = [
"$mod SHIFT, V, exec, ${picker}" {
_args = [
(lib.generators.mkLuaInline ''mod .. " + SHIFT + V"'')
(lib.generators.mkLuaInline "hl.dsp.exec_cmd(${builtins.toJSON picker})")
];
}
]; ];
}; };
}; };

View File

@@ -45,9 +45,13 @@ in
config = lib.mkIf config.modules.desktop.utilities.recording.enable { config = lib.mkIf config.modules.desktop.utilities.recording.enable {
home-manager.users.${user} = { home-manager.users.${user} = {
# $mod is defined by the compositor config these binds share.
wayland.windowManager.hyprland.settings.bind = [ wayland.windowManager.hyprland.settings.bind = [
"$mod SHIFT, R, exec, ${toggle}" {
_args = [
(lib.generators.mkLuaInline ''mod .. " + SHIFT + R"'')
(lib.generators.mkLuaInline "hl.dsp.exec_cmd(${builtins.toJSON toggle})")
];
}
]; ];
}; };
}; };

View File

@@ -38,21 +38,34 @@ in
config = lib.mkIf config.modules.desktop.utilities.screenshot.enable { config = lib.mkIf config.modules.desktop.utilities.screenshot.enable {
home-manager.users.${user} = { home-manager.users.${user} = {
# satty is a one-shot annotation surface, so float it rather than letting # Satty is a one-shot annotation surface, so it floats above the layout.
# it claim a tile in the layout. wayland.windowManager.hyprland.settings.window_rule = {
# windowrule v3 syntax: space-separated field/value tokens, comma float = true;
# separated, with matchers under a match: prefix and effects bare. match.class = "^(com\\.gabm\\.satty)$";
wayland.windowManager.hyprland.settings.windowrule = [ };
"float 1, match:class ^(com\\.gabm\\.satty)$"
];
# Print with plain/Shift/Ctrl for region/window/full. # Print with plain/Shift/Ctrl for region/window/full.
# Super+L is already the hjkl focus and movement bind, so screenshots take # Super+L is already the hjkl focus and movement bind, so screenshots take
# the Print key instead. # the Print key instead.
wayland.windowManager.hyprland.settings.bind = [ wayland.windowManager.hyprland.settings.bind = [
", Print, exec, ${capture "area"}" {
"SHIFT, Print, exec, ${capture "active"}" _args = [
"CTRL, Print, exec, ${capture "screen"}" "PRINT"
(lib.generators.mkLuaInline "hl.dsp.exec_cmd(${builtins.toJSON (capture "area")})")
];
}
{
_args = [
"SHIFT + PRINT"
(lib.generators.mkLuaInline "hl.dsp.exec_cmd(${builtins.toJSON (capture "active")})")
];
}
{
_args = [
"CTRL + PRINT"
(lib.generators.mkLuaInline "hl.dsp.exec_cmd(${builtins.toJSON (capture "screen")})")
];
}
]; ];
}; };
}; };