mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
hyprland: add extraLuaFiles option
Allow Lua configs to be split across managed files under XDG_CONFIG_HOME/hypr.
Treat extraLuaFiles attribute names as Lua module names, so dotted names such as lib.helpers write lib/helpers.lua while autoloading with require("lib.helpers").
Add assertions for invalid configType usage, generated hyprland.lua collisions, and duplicate resolved Lua file targets.
This commit is contained in:
@@ -15,4 +15,6 @@ lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
||||
hyprland-submaps-config = ./submaps-config.nix;
|
||||
hyprland-submaps-on-dispatch = ./submaps-on-dispatch.nix;
|
||||
hyprland-lua-config = ./lua-config.nix;
|
||||
hyprland-lua-files-assertions = ./lua-files-assertions.nix;
|
||||
hyprland-lua-files-config = ./lua-files-config.nix;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
};
|
||||
|
||||
test.asserts.warnings.expected = [
|
||||
"You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings, hyprland.extraConfig or hyprland.submaps. This is almost certainly a mistake."
|
||||
"You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings, hyprland.extraConfig, hyprland.extraLuaFiles or hyprland.submaps. This is almost certainly a mistake."
|
||||
];
|
||||
test.asserts.warnings.enable = true;
|
||||
|
||||
|
||||
3
tests/modules/services/hyprland/lua-file-from-path.lua
Normal file
3
tests/modules/services/hyprland/lua-file-from-path.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
hl.on("hyprland.start", function()
|
||||
hl.exec_cmd("waybar")
|
||||
end)
|
||||
3
tests/modules/services/hyprland/lua-files-00-vars.lua
Normal file
3
tests/modules/services/hyprland/lua-files-00-vars.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
local M = {}
|
||||
M.mainMod = "SUPER"
|
||||
return M
|
||||
21
tests/modules/services/hyprland/lua-files-assertions.nix
Normal file
21
tests/modules/services/hyprland/lua-files-assertions.nix
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
wayland.windowManager.hyprland = {
|
||||
enable = true;
|
||||
configType = "hyprlang";
|
||||
package = null;
|
||||
portalPackage = null;
|
||||
|
||||
extraLuaFiles = {
|
||||
foo = "";
|
||||
"foo.lua" = "";
|
||||
hyprland = "";
|
||||
};
|
||||
};
|
||||
|
||||
test.asserts.assertions.expected = [
|
||||
"wayland.windowManager.hyprland.extraLuaFiles cannot define hyprland.lua because it is generated by the Hyprland module."
|
||||
"wayland.windowManager.hyprland.extraLuaFiles contains entries that resolve to the same Lua file path."
|
||||
];
|
||||
|
||||
test.asserts.warnings.enable = false;
|
||||
}
|
||||
2
tests/modules/services/hyprland/lua-files-bindings.lua
Normal file
2
tests/modules/services/hyprland/lua-files-bindings.lua
Normal file
@@ -0,0 +1,2 @@
|
||||
local vars = require("00-vars")
|
||||
hl.bind(vars.mainMod .. " + RETURN", hl.dsp.exec_cmd("kitty"))
|
||||
9
tests/modules/services/hyprland/lua-files-config.lua
Normal file
9
tests/modules/services/hyprland/lua-files-config.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
-- Generated by Home Manager.
|
||||
-- See https://wiki.hypr.land/Configuring/Start/
|
||||
|
||||
-- extraLuaFiles
|
||||
local hm_xdg_config_home = os.getenv("XDG_CONFIG_HOME") or "/home/hm-user/.config"
|
||||
package.path = hm_xdg_config_home .. "/hypr/?.lua;" .. hm_xdg_config_home .. "/hypr/?/init.lua;" .. package.path
|
||||
require("00-vars")
|
||||
require("from-path")
|
||||
require("ui.bindings")
|
||||
59
tests/modules/services/hyprland/lua-files-config.nix
Normal file
59
tests/modules/services/hyprland/lua-files-config.nix
Normal file
@@ -0,0 +1,59 @@
|
||||
_:
|
||||
|
||||
{
|
||||
wayland.windowManager.hyprland = {
|
||||
enable = true;
|
||||
configType = "lua";
|
||||
package = null;
|
||||
portalPackage = null;
|
||||
|
||||
systemd.enable = false;
|
||||
|
||||
extraLuaFiles = {
|
||||
"00-vars" = ''
|
||||
local M = {}
|
||||
M.mainMod = "SUPER"
|
||||
return M
|
||||
'';
|
||||
|
||||
"ui.bindings" = {
|
||||
content = ''
|
||||
local vars = require("00-vars")
|
||||
hl.bind(vars.mainMod .. " + RETURN", hl.dsp.exec_cmd("kitty"))
|
||||
'';
|
||||
};
|
||||
|
||||
"lib.helpers" = {
|
||||
content = ''
|
||||
local M = {}
|
||||
M.terminal = "kitty"
|
||||
return M
|
||||
'';
|
||||
autoLoad = false;
|
||||
};
|
||||
|
||||
"from-path.lua" = ./lua-file-from-path.lua;
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
config=home-files/.config/hypr/hyprland.lua
|
||||
assertFileExists "$config"
|
||||
assertPathNotExists home-files/.config/hypr/hyprland.conf
|
||||
assertPathNotExists home-files/.config/hypr/.luarc.json
|
||||
|
||||
assertFileContent "$config" ${./lua-files-config.lua}
|
||||
|
||||
assertFileContent home-files/.config/hypr/00-vars.lua \
|
||||
${./lua-files-00-vars.lua}
|
||||
|
||||
assertFileContent home-files/.config/hypr/ui/bindings.lua \
|
||||
${./lua-files-bindings.lua}
|
||||
|
||||
assertFileContent home-files/.config/hypr/lib/helpers.lua \
|
||||
${./lua-files-helpers.lua}
|
||||
|
||||
assertFileContent home-files/.config/hypr/from-path.lua \
|
||||
${./lua-file-from-path.lua}
|
||||
'';
|
||||
}
|
||||
3
tests/modules/services/hyprland/lua-files-helpers.lua
Normal file
3
tests/modules/services/hyprland/lua-files-helpers.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
local M = {}
|
||||
M.terminal = "kitty"
|
||||
return M
|
||||
Reference in New Issue
Block a user