hyprland: fix plugin loading when using lua

Move plugin loading to the top of the rendered ~/.config/hypr/hyprland.lua as plugins must be loaded before hl.config can be called with config keys added by the plugin, (binds using dispatchers added by plugins also fail if they are defined before the plugin is loaded)

This also switches over to using the (undocumented?) hl.plugin.load("/path/to/plugin.so") to load plugins, which has solved some strange race condition weirdness caused by using exec_cmd with hyprctl plugin load (I first tried moving renderStartHook to the top of the rendered config, but sometimes it seemed the hyprctl plugin load wouldn't finish loading the plugin before the rest of the config was loaded, causing the same errors about unknown config keys)
This commit is contained in:
DrymarchonShaun
2026-06-18 22:39:21 -05:00
committed by GitHub
parent 3abeedcf40
commit 266211649f
2 changed files with 10 additions and 5 deletions
@@ -128,9 +128,11 @@ in
xdgConfigHome, xdgConfigHome,
}: }:
let let
pluginLoadCommands = map (entry: "hyprctl plugin load ${pluginPath entry}") config.plugins; renderPluginLoad = renderSection "plugins" (
startupCommands = concatMapStrings (entry: "hl.plugin.load(${toLua (pluginPath entry)})\n") config.plugins
lib.optionals config.systemd.enable [ systemdActivationCommand ] ++ pluginLoadCommands; );
startupCommands = lib.optionals config.systemd.enable [ systemdActivationCommand ];
renderSettings = renderSettings =
let let
@@ -225,6 +227,7 @@ in
-- See https://wiki.hypr.land/Configuring/Start/ -- See https://wiki.hypr.land/Configuring/Start/
'' ''
+ renderPluginLoad
+ renderLuaFiles + renderLuaFiles
+ renderSettings + renderSettings
+ renderSubmaps + renderSubmaps
@@ -1,6 +1,10 @@
-- Generated by Home Manager. -- Generated by Home Manager.
-- See https://wiki.hypr.land/Configuring/Start/ -- See https://wiki.hypr.land/Configuring/Start/
-- plugins
hl.plugin.load("/path/to/plugin1")
hl.plugin.load("/nix/store/00000000000000000000000000000000-foo/lib/libfoo.so")
-- settings.locals -- settings.locals
local mod = "SUPER" local mod = "SUPER"
local terminal = "kitty" local terminal = "kitty"
@@ -136,8 +140,6 @@ end)
-- startup -- startup
hl.on("hyprland.start", function() hl.on("hyprland.start", function()
hl.exec_cmd("@dbus@/bin/dbus-update-activation-environment --systemd DISPLAY HYPRLAND_INSTANCE_SIGNATURE WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_TYPE && systemctl --user stop hyprland-session.target && systemctl --user start hyprland-session.target") hl.exec_cmd("@dbus@/bin/dbus-update-activation-environment --systemd DISPLAY HYPRLAND_INSTANCE_SIGNATURE WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_TYPE && systemctl --user stop hyprland-session.target && systemctl --user start hyprland-session.target")
hl.exec_cmd("hyprctl plugin load /path/to/plugin1")
hl.exec_cmd("hyprctl plugin load /nix/store/00000000000000000000000000000000-foo/lib/libfoo.so")
end) end)
-- extraConfig -- extraConfig