Honour XDG_CONFIG_HOME in Hyprland Lua loaders #96

Open
Breadway wants to merge 2 commits from fix/bos-82-lua-xdg-config-home into main
Owner

How it was found

BOS-82 (medium confidence, reported from a sandboxed nested Hyprland session). Confirmed from source: hyprland.lua and five loaders (display/monitors.lua, input/binds.lua, system/autostart.lua, ui/rules.lua, ui/settings.lua) built paths from os.getenv("HOME") .. "/.config/hypr/". bos-settings writes through dirs::config_dir(), which honours XDG_CONFIG_HOME, so with XDG_CONFIG_HOME set, Settings writes never reached the files Hyprland reads.

What changed

  • scripts/lib/paths.lua (new): the one place the config dir is resolved. Uses XDG_CONFIG_HOME when it is an absolute path (empty or relative values are ignored, trailing slashes trimmed), else $HOME/.config.
  • hyprland.lua: loads paths.lua from its own directory and sets BOS_HYPR_DIR once. script_dir, config_home and the nvidia.lua path use it.
  • The five loaders read BOS_HYPR_DIR instead of their own $HOME string.
  • scripts/test-hypr-config-home.lua (new): standalone check, runs under plain lua or luajit, no Hyprland. Stages a copy of the shipped tree twice (XDG and HOME), loads hyprland.lua with a stubbed hl API, fires hyprland.start, and asserts each JSON read comes from the right dir. Also asserts no loader builds $HOME/.config itself.
  • CHANGELOG line under [Unreleased].

Behaviour is unchanged when XDG_CONFIG_HOME is unset.

Tests

  • lua scripts/test-hypr-config-home.lua: 18 passed, 0 failed.
  • luajit scripts/test-hypr-config-home.lua: 18 passed, 0 failed.
  • luac -p / loadfile syntax check on every hypr Lua file: pass.
  • Not run: anything against a live or nested Hyprland. The stubbed hl API means this checks paths and load order, not Hyprland's acceptance of the values.

Refs BOS-82

## How it was found BOS-82 (medium confidence, reported from a sandboxed nested Hyprland session). Confirmed from source: `hyprland.lua` and five loaders (`display/monitors.lua`, `input/binds.lua`, `system/autostart.lua`, `ui/rules.lua`, `ui/settings.lua`) built paths from `os.getenv("HOME") .. "/.config/hypr/"`. bos-settings writes through `dirs::config_dir()`, which honours XDG_CONFIG_HOME, so with XDG_CONFIG_HOME set, Settings writes never reached the files Hyprland reads. ## What changed - `scripts/lib/paths.lua` (new): the one place the config dir is resolved. Uses XDG_CONFIG_HOME when it is an absolute path (empty or relative values are ignored, trailing slashes trimmed), else `$HOME/.config`. - `hyprland.lua`: loads paths.lua from its own directory and sets `BOS_HYPR_DIR` once. `script_dir`, `config_home` and the nvidia.lua path use it. - The five loaders read `BOS_HYPR_DIR` instead of their own `$HOME` string. - `scripts/test-hypr-config-home.lua` (new): standalone check, runs under plain lua or luajit, no Hyprland. Stages a copy of the shipped tree twice (XDG and HOME), loads `hyprland.lua` with a stubbed `hl` API, fires `hyprland.start`, and asserts each JSON read comes from the right dir. Also asserts no loader builds `$HOME/.config` itself. - CHANGELOG line under [Unreleased]. Behaviour is unchanged when XDG_CONFIG_HOME is unset. ## Tests - `lua scripts/test-hypr-config-home.lua`: 18 passed, 0 failed. - `luajit scripts/test-hypr-config-home.lua`: 18 passed, 0 failed. - `luac -p` / loadfile syntax check on every hypr Lua file: pass. - Not run: anything against a live or nested Hyprland. The stubbed `hl` API means this checks paths and load order, not Hyprland's acceptance of the values. Refs BOS-82
The Lua loaders built every path from $HOME/.config/hypr, while bos-settings
writes its JSON through dirs::config_dir(), which honours XDG_CONFIG_HOME.
With XDG_CONFIG_HOME set, Settings changes were saved where Hyprland never
read them.

Resolve the config dir once in scripts/lib/paths.lua (XDG_CONFIG_HOME when
absolute, otherwise $HOME/.config) and have hyprland.lua and each loader
use it. Behaviour is unchanged when XDG_CONFIG_HOME is unset.

Add scripts/test-hypr-config-home.lua, a standalone check that runs under
plain lua or luajit against a staged copy of the shipped tree.

Refs BOS-82
Refs BOS-82
Author
Owner

Unverified assumption (found after the PR was opened): hyprland.lua locates scripts/lib/paths.lua with debug.getinfo(1, "S").source. That only works if Hyprland loads the config as a file chunk (source starting with "@"). If Hyprland loads it from a string, the fallback is "." and dofile fails at the top of hyprland.lua, which would stop the whole config. The standalone test loads the file directly, so it does not cover this. Not verified against a live or nested Hyprland. Needs a check in a private nested session before merge, or a fallback to the XDG/HOME rule if source is not a path.

Unverified assumption (found after the PR was opened): hyprland.lua locates scripts/lib/paths.lua with debug.getinfo(1, "S").source. That only works if Hyprland loads the config as a file chunk (source starting with "@"). If Hyprland loads it from a string, the fallback is "." and dofile fails at the top of hyprland.lua, which would stop the whole config. The standalone test loads the file directly, so it does not cover this. Not verified against a live or nested Hyprland. Needs a check in a private nested session before merge, or a fallback to the XDG/HOME rule if source is not a path.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix/bos-82-lua-xdg-config-home:fix/bos-82-lua-xdg-config-home
git switch fix/bos-82-lua-xdg-config-home

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff fix/bos-82-lua-xdg-config-home
git switch fix/bos-82-lua-xdg-config-home
git rebase main
git switch main
git merge --ff-only fix/bos-82-lua-xdg-config-home
git switch fix/bos-82-lua-xdg-config-home
git rebase main
git switch main
git merge --no-ff fix/bos-82-lua-xdg-config-home
git switch main
git merge --squash fix/bos-82-lua-xdg-config-home
git switch main
git merge --ff-only fix/bos-82-lua-xdg-config-home
git switch main
git merge fix/bos-82-lua-xdg-config-home
git push origin main
Sign in to join this conversation.
No description provided.