From 8c1687fa8319ffadc227e58a222b4cabc3930c38 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Fri, 8 May 2026 02:35:32 -0700 Subject: [PATCH] checks: extract hyprland config smoke test --- .../checks/hyprland-config-syntax/default.nix | 18 +++ .../hyprland-config-syntax/smoke-test.lua | 110 +++++++++++++++ nixos/flake.nix | 127 +----------------- 3 files changed, 132 insertions(+), 123 deletions(-) create mode 100644 nixos/checks/hyprland-config-syntax/default.nix create mode 100644 nixos/checks/hyprland-config-syntax/smoke-test.lua diff --git a/nixos/checks/hyprland-config-syntax/default.nix b/nixos/checks/hyprland-config-syntax/default.nix new file mode 100644 index 00000000..63467e0a --- /dev/null +++ b/nixos/checks/hyprland-config-syntax/default.nix @@ -0,0 +1,18 @@ +{ + pkgs, + hyprlandConfig, +}: +pkgs.runCommand "hyprland-config-syntax" { + nativeBuildInputs = [pkgs.lua5_4]; +} '' + cp ${hyprlandConfig} hyprland.lua + luac -p hyprland.lua + + if grep -n 'hyprctl' hyprland.lua | grep -v 'hyprctl reload' | grep -v 'hyprctl eval' | grep -v 'hyprctl_eval' | grep -v 'hyprctl -j monitors'; then + echo "hyprland.lua should not shell out to hyprctl for window/workspace manipulation" >&2 + exit 1 + fi + + lua ${./smoke-test.lua} ./hyprland.lua + touch "$out" +'' diff --git a/nixos/checks/hyprland-config-syntax/smoke-test.lua b/nixos/checks/hyprland-config-syntax/smoke-test.lua new file mode 100644 index 00000000..f476d83b --- /dev/null +++ b/nixos/checks/hyprland-config-syntax/smoke-test.lua @@ -0,0 +1,110 @@ +local config_path = arg[1] or "./hyprland.lua" +local callbacks = {} + +local function noop() end + +local function dispatcher_proxy() + local proxy = {} + return setmetatable(proxy, { + __index = function() + return dispatcher_proxy() + end, + __call = function() + return noop + end, + }) +end + +local notification = { + is_alive = function() + return true + end, + set_text = noop, + set_timeout = noop, + pause = noop, + resume = noop, + set_paused = noop, + dismiss = noop, +} + +local monitor = { + id = 1, + name = "stub-monitor", + focused = true, +} + +local workspace = { + id = 1, + name = "1", + windows = 0, + special = false, + monitor = monitor, +} + +monitor.active_workspace = workspace + +hl = { + animation = noop, + bind = noop, + config = noop, + curve = noop, + env = noop, + exec_cmd = noop, + define_submap = function(_, reset_or_callback, callback) + local cb = type(reset_or_callback) == "function" and reset_or_callback or callback + if cb then + cb() + end + end, + monitor = noop, + workspace_rule = noop, + window_rule = noop, + dsp = dispatcher_proxy(), + notification = { + create = function() + return notification + end, + }, + plugin = { + load = noop, + }, + get_active_workspace = function() + return workspace + end, + get_active_monitor = function() + return monitor + end, + get_active_window = function() + return nil + end, + get_monitor = function() + return monitor + end, + get_workspace = function(id) + if tostring(id) == "1" then + return workspace + end + return nil + end, + get_windows = function() + return {} + end, + get_workspace_windows = function() + return {} + end, + on = function(_, callback) + callbacks[#callbacks + 1] = callback + end, + timer = function(callback) + callback() + return { + set_enabled = noop, + } + end, +} + +dofile(config_path) + +for _, callback in ipairs(callbacks) do + callback() +end diff --git a/nixos/flake.nix b/nixos/flake.nix index 497ef110..e9a9524e 100644 --- a/nixos/flake.nix +++ b/nixos/flake.nix @@ -546,129 +546,10 @@ hyprexpo-lua = inputs.hyprland-plugins-lua.packages.${system}.hyprexpo; hyprwinview = inputs.hyprwinview.packages.${system}.hyprwinview; hypr-workspace-history = inputs.hypr-workspace-history.packages.${system}.hypr-workspace-history; - hyprland-config-syntax = - pkgs.runCommand "hyprland-config-syntax" { - nativeBuildInputs = [pkgs.lua5_4]; - } '' - cp ${../dotfiles/config/hypr/hyprland.lua} hyprland.lua - luac -p hyprland.lua - if grep -n 'hyprctl' hyprland.lua | grep -v 'hyprctl reload' | grep -v 'hyprctl eval' | grep -v 'hyprctl_eval' | grep -v 'hyprctl -j monitors'; then - echo "hyprland.lua should not shell out to hyprctl for window/workspace manipulation" >&2 - exit 1 - fi - lua <<'LUA' - local callbacks = {} - - local function noop() end - - local function dispatcher_proxy() - local proxy = {} - return setmetatable(proxy, { - __index = function() - return dispatcher_proxy() - end, - __call = function() - return noop - end, - }) - end - - local notification = { - is_alive = function() - return true - end, - set_text = noop, - set_timeout = noop, - pause = noop, - resume = noop, - set_paused = noop, - dismiss = noop, - } - - local monitor = { - id = 1, - name = "stub-monitor", - focused = true, - } - - local workspace = { - id = 1, - name = "1", - windows = 0, - special = false, - monitor = monitor, - } - - monitor.active_workspace = workspace - - hl = { - animation = noop, - bind = noop, - config = noop, - curve = noop, - env = noop, - exec_cmd = noop, - define_submap = function(_, reset_or_callback, callback) - local cb = type(reset_or_callback) == "function" and reset_or_callback or callback - if cb then - cb() - end - end, - monitor = noop, - workspace_rule = noop, - window_rule = noop, - dsp = dispatcher_proxy(), - notification = { - create = function() - return notification - end, - }, - plugin = { - load = noop, - }, - get_active_workspace = function() - return workspace - end, - get_active_monitor = function() - return monitor - end, - get_active_window = function() - return nil - end, - get_monitor = function() - return monitor - end, - get_workspace = function(id) - if tostring(id) == "1" then - return workspace - end - return nil - end, - get_windows = function() - return {} - end, - get_workspace_windows = function() - return {} - end, - on = function(_, callback) - callbacks[#callbacks + 1] = callback - end, - timer = function(callback) - callback() - return { - set_enabled = noop, - } - end, - } - - dofile("./hyprland.lua") - - for _, callback in ipairs(callbacks) do - callback() - end - LUA - touch "$out" - ''; + hyprland-config-syntax = import ./checks/hyprland-config-syntax { + inherit pkgs; + hyprlandConfig = ../dotfiles/config/hypr/hyprland.lua; + }; hyprland-verify-config = let hyprlandPackage = inputs.hyprland.packages.${system}.hyprland; hyprNStackPackage = inputs.hyprNStack.packages.${system}.hyprNStack;