fix(nix): Kanary の Caps Lock→Control を宣言的に強制する - #972
Conversation
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
Warning Review limit reached
Next review available in: 53 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughAdds a Home Manager module and macOS helper that enforce Kanary’s Caps Lock-to-Control setting during activation, update Kanary’s settings safely, restart Kanary when needed, document remapping ownership, and test the configuration wiring. ChangesKanary Caps Lock control
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@script/macos/kanary-enforce-caps-control.sh`:
- Line 82: Replace the `pgrep -x Kanary && pkill -9 -x Kanary || true` construct
with an explicit if statement in the Kanary termination logic, so `pkill` runs
only when `pgrep` finds the process and the fallback does not execute merely
because `pkill` fails.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 73bbd1dc-e97a-4fba-85b2-f10dafa9bd94
📒 Files selected for processing (5)
docs/adr/0016-use-kanary-for-keyboard-remapping.mdnix/home/default.nixnix/home/kanary.nixscript/macos/kanary-enforce-caps-control.shtest/nix-darwin-config.test.js
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2798934a4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| home.activation.enforceKanaryCapsControl = lib.hm.dag.entryAfter [ "writeBoundary" ] '' | ||
| $DRY_RUN_CMD "${config.home.homeDirectory}/.local/bin/kanary-enforce-caps-control" || true |
There was a problem hiding this comment.
Run the Kanary hook after home-file linking
On the first darwin-rebuild switch that includes this module, the target in ~/.local/bin has not necessarily been created yet: Home Manager links home.file entries in its linkGeneration activation step, which is also only ordered after writeBoundary, so this new step has no dependency on the link being present. Because the command's failure is swallowed with || true, the initial activation can silently leave capsLockRemappedToControl unchanged until a later switch; order this after linkGeneration or invoke the store path directly.
Useful? React with 👍 / 👎.
| plutil -extract app_settings raw -o - "$PLIST" 2>/dev/null \ | ||
| | base64 -D 2>/dev/null \ | ||
| | python3 -c 'import sys, json |
There was a problem hiding this comment.
Resolve macOS utilities instead of activation PATH entries
When this helper is invoked from Home Manager activation, this repo's home.stateVersion = "24.11" means activation starts with a restricted PATH containing Nix tools, not /usr/bin. In that context plutil/python3/later defaults may not be found, and base64 resolves to GNU coreutils, whose help lists decoding as -d, --decode rather than macOS -D; for any activation where the Kanary setting is false, the script will skip or fail before writing while the activation masks the failure. Use absolute /usr/bin/... paths or decode/update the plist entirely via a known Nix/Python dependency.
Useful? React with 👍 / 👎.
Kanary intercepts the physical keyboard and re-emits events through a virtual HID device when its window/input features are enabled, which bypasses the global hidutil mapping from system.keyboard.remapCapsLockToControl. Caps Lock therefore reverts to Caps Lock unless Kanary's own capsLockRemappedToControl is true. - Add script/macos/kanary-enforce-caps-control.sh: idempotent helper that flips only that one field to true and restarts Kanary on drift, and is a silent no-op once correct. - Add nix/home/kanary.nix: install the helper and re-assert on every home-manager activation. Wire it into nix/home/default.nix. - Correct ADR 0016 to reflect that the hidutil baseline is bypassed by Kanary and that Caps→Control is owned by Kanary's setting. - Add a test covering the enforcement wiring.
d279893 to
1f7a6fe
Compare
|
🎉 This PR is included in version 1.123.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Why(背景)
system.keyboard.remapCapsLockToControl = true(nix-darwin / hidutil)を設定済みにもかかわらず、実機で Caps Lock が Control にならず Caps Lock のままになる事象が発生。調査の結果、Kanary が原因と判明:
0x5ac 0x8600)経由でイベントを再送出するcapsLockRemappedToControlがfalseだったため、Caps がそのまま通っていたADR 0016 は「Caps→Ctrl は hidutil が担当し、Kanary 設定前でも効く」としていたが、実機ではこの前提が成立しない。
What(変更内容)
script/macos/kanary-enforce-caps-control.sh: 冪等な自己修復ヘルパーcapsLockRemappedToControlが既にtrueならサイレント no-opfalseを検知した時のみ、plist をバックアップ→当該1フィールドのみ true 化→(起動中なら)Kanary 再起動nix/home/kanary.nix: ヘルパーを~/.local/binに設置し、home-manager の activation(writeBoundary後)で毎回再適用。nix/home/default.nixに import 追加docs/adr/0016: hidutil ベースラインが Kanary にバイパスされる実態と、Caps→Control を Kanary 側で所有・強制する方針に修正How(検証)
darwin-rebuild build --flake ./nix#keitonoMacBook-Pro→ 成功(home-manager activation まで生成)shellcheck -x→ PASSjest test/nix-darwin-config.test.js→ 17 passed(新テスト含む)prettier --check(md)→ PASS /nixfmt(nix)適用済みRisk / Notes
capsLockRemappedToControlの1フィールドのみ(voice 等の他設定は非改変).git/configがcore.bare=trueに破損、Mac のホスト名がaに変わっていた環境ドリフトも確認・修復済み。ホスト名を nix で宣言管理する hardening は必要なら別PRで対応可能Summary by CodeRabbit
New Features
Documentation
Tests