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 20:39:21 -07:00 committed by GitHub
parent 3abeedcf40
commit 266211649f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View file

@ -128,9 +128,11 @@ in
xdgConfigHome,
}:
let
pluginLoadCommands = map (entry: "hyprctl plugin load ${pluginPath entry}") config.plugins;
startupCommands =
lib.optionals config.systemd.enable [ systemdActivationCommand ] ++ pluginLoadCommands;
renderPluginLoad = renderSection "plugins" (
concatMapStrings (entry: "hl.plugin.load(${toLua (pluginPath entry)})\n") config.plugins
);
startupCommands = lib.optionals config.systemd.enable [ systemdActivationCommand ];
renderSettings =
let
@ -225,6 +227,7 @@ in
-- See https://wiki.hypr.land/Configuring/Start/
''
+ renderPluginLoad
+ renderLuaFiles
+ renderSettings
+ renderSubmaps

View file

@ -1,6 +1,10 @@
-- Generated by Home Manager.
-- 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
local mod = "SUPER"
local terminal = "kitty"
@ -136,8 +140,6 @@ end)
-- startup
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("hyprctl plugin load /path/to/plugin1")
hl.exec_cmd("hyprctl plugin load /nix/store/00000000000000000000000000000000-foo/lib/libfoo.so")
end)
-- extraConfig