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:
Austin Horstman
2026-05-14 10:15:57 -05:00
parent 5148001968
commit a6a13bb0a0
11 changed files with 234 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -0,0 +1,3 @@
hl.on("hyprland.start", function()
hl.exec_cmd("waybar")
end)

View File

@@ -0,0 +1,3 @@
local M = {}
M.mainMod = "SUPER"
return M

View 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;
}

View File

@@ -0,0 +1,2 @@
local vars = require("00-vars")
hl.bind(vars.mainMod .. " + RETURN", hl.dsp.exec_cmd("kitty"))

View 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")

View 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}
'';
}

View File

@@ -0,0 +1,3 @@
local M = {}
M.terminal = "kitty"
return M