feat(macos): start working towards having shortcuts configuration#52
Open
feat(macos): start working towards having shortcuts configuration#52
Conversation
This is inspired by https://github.com/nix-darwin/nix-darwin/pull/699/changes. It however simplifies the process by fixing all the "magic" values and only really needing to do basic addition for the mods and then string conversions. Currently it only outputs it to a file, next step is to start checking if it actually works to run against the actual system. As mentionned in nix-darwin/nix-darwin#699 (comment), I will use `defaults write com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add magicNumber "<dict></dict>"` instead.
Currently it doesn't make the changes, but maybe on restart it will?
This is fun ok? I'm doing this to myself with enthusiasm!
nobe4
added a commit
to nobe4/nix-darwin
that referenced
this pull request
Mar 30, 2026
This adds support for configuring keyboard shortcuts directly into nix-darwin. This is not a new idea, but this looks like the only implementation that does it consistently, whilst introducing a very large number of options whilst keeping the default values available. This works by: - Create a mapping of all mods / keys. See `keycodes.nix`. I decided here to have the 'decimal' + 'ascii' values hard-coded. This took a while to get, but should save on future "maths" to get them. The keycodes are ordered directly from the source header file for consistency. In the future, I might use an AI for this, as it's a "simple translation". - Create a mapping of all* the available mappings and their default state/shortcuts. This enables a comprehensive list, ordered by Apple's sections. This also allows to "reset to defaults" if needed. Without a change, the default state/shortcuts will be used, which should create minimal friction for new users. - Add a `disableAll` toggle in case you don't want any of the default shortcuts. This is my case and I was really happy to see that I could just yeet all the defaults out, to only enable the ones I want. *: the list was compiled on my personal macbook, which is a 2020 intel with the touchbar. So I might not have all the configuration options. However it would be really easy to add new, since they all map to a unique ID. AFAIK, this is a good to go PR with no extra work needed. But I would appreciate any feedback nevertheless. This draws on inspiration from nix-darwin#699 and various online sources (commented in the code whenever necessary). This is also a single commit that is a direct `cp` of the head of nobe4/dotfiles#52, plus minor adjustments for inclusion into this repo. I use `nixfmt` extensively btw, hence the formatting. And until (if) NixOS/nixfmt#91 is solved I will format all my files 🤷.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is inspired by https://github.com/nix-darwin/nix-darwin/pull/699/changes. It however simplifies the process by fixing all the "magic" values and only really needing to do basic addition for the mods and then string conversions.
The current state is: working, and now only need to specify the
defaults.As mentionned in
nix-darwin/nix-darwin#699 (comment), I will use
defaults write com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add magicNumber "<dict></dict>"instead.