blog.anqou.net
rss
author
tags

Hyprland on NixOS の設定を Lua に移行する

先日の NixOS 26.05 への以降の際に Hyprland の設定ファイルの形式が従来の hyprlang から Lua に変更されたことを知りました。 hyprlang もしばらくは使い続けられるようですがそのうちサポートが打ち切られるとのことなので、手元の設定も Lua に移行しました。

既に Hyprland のドキュメントは Lua のものに移行されています。また example config も用意されているので、これらを見ながら設定を移行します。ただし、Lua のサポートの完全なリファレンスがあるわけではないので、ドキュメントにも example config にもないようなものは Hyprland の実装を見ながらエスパーして設定を行う必要があります[1]。 Hyprland の GitHub repo の src/config/lua/bindings 配下のコードが Lua 周りの実装になっているようです。

手元で使っていた機能のうち、ドキュメント・example config に無く困ったものを以下にまとめます:

-- bind = $mainMod, 1, focusmonitor, $leftMonitor
hl.bind(mainMod .. " + 1", hl.dsp.focus({ monitor = leftMonitor }))

-- bind = $mainMod, F1, movewindow, mon:$leftMonitor
hl.bind(mainMod .. " + F1", hl.dsp.window.move({ monitor = leftMonitor }))

-- bind = $mainMod SHIFT, H, movewindow, l
hl.bind(mainMod .. " + SHIFT + H", hl.dsp.window.move({ direction = "left" }))

-- bind = $mainMod, R, swapactiveworkspaces, 0 1
hl.bind(mainMod .. " + R", hl.dsp.workspace.swap_monitors({ monitor1 = leftMonitor, monitor2 = rightMonitor }))

-- bind = $mainMod SHIFT, Q, killactive,
hl.bind(mainMod .. " + SHIFT + Q", hl.dsp.window.close())

-- cursor {
--     no_hardware_cursors = true
-- }
-- xwayland {
--   force_zero_scaling = true
-- }
-- debug {
--   disable_logs = false
-- }
-- misc {
--   disable_splash_rendering = true
--   disable_hyprland_logo = true
-- }
hl.config({
  cursor = {
    no_hardware_cursors = true,
  },
  xwayland = {
    force_zero_scaling = true
  },
  debug = {
    disable_logs = false,
  },
  misc = {
    disable_splash_rendering = true,
    disable_hyprland_logo = true
  },
})

ところで Home Manager も Hyprland の Lua による設定に対応していて wayland.windowManager.hyprland.settings を使うと Nix 式として hl.config(...) を書けるようになっています。ただ、hl.config(...) の形式が強制される都合上、使いにくいような気がしています。ということで手元では home.file を使って .config/hypr 配下に Lua ファイルを symlink として配置した後に、 wayland.windowManager.hyprland.extraConfig 経由で require(...) を注入するような形にしてみました。 config.lib.file.mkOutOfStoreSymlink を経由することで Nix の管理からは外れますが、代わりにファイルを書き換えると即座に(nixos-rebuild switch を実行することなく)設定が反映されるので便利です:

home = {
  file = {
    ".config/hypr/custom.lua" = {
      target = ".config/hypr/custom.lua";
      source = config.lib.file.mkOutOfStoreSymlink /path/to/hyprland.lua;
    };
  };
};
wayland.windowManager.hyprland = {
  enable = true;
  configType = "lua";
  extraConfig = ''require("custom")'';
};

注釈

  1. GLM-5.2 に Hyprland の実装を読んでもらうのが楽でした。