-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
home-manager/remap-keys: allow customization of mappings
- Loading branch information
1 parent
8750506
commit ae14f97
Showing
4 changed files
with
64 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
let | ||
cfg = config.home-manager.darwin.remapKeys; | ||
in | ||
{ | ||
options.home-manager.darwin.remapKeys = { | ||
# https://gist.github.com/paultheman/808be117d447c490a29d6405975d41bd | ||
mappings = lib.mkOption { | ||
description = "Remap keyboard keys (requires sudo)."; | ||
type = with lib.types; attrsOf str; | ||
default = { }; | ||
example = { | ||
# '§±' <-> '`~' | ||
"0x700000035" = "0x700000064"; | ||
"0x700000064" = "0x700000035"; | ||
}; | ||
}; | ||
productID = lib.mkOption { | ||
description = "Product ID to remap (use `hidutil list` to get all of them)."; | ||
type = lib.types.str; | ||
# Apple Internal Keyboard / Trackpad | ||
default = "0x343"; | ||
}; | ||
vendorID = lib.mkOption { | ||
description = "Vendor ID to remap (use `hidutil list` to get all of them)."; | ||
type = lib.types.str; | ||
# Apple | ||
default = "0x5ac"; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf (cfg.mappings != { }) { | ||
home.activation.remapKeys = lib.hm.dag.entryAfter [ "writeBoundary" ] /* bash */ '' | ||
source="${pkgs.substituteAll { | ||
inherit (cfg) productID vendorID; | ||
src = ./remap-keys.plist; | ||
remappings = lib.pipe cfg.mappings [ | ||
(lib.mapAttrsToList | ||
(src: dst: /* json */ | ||
''{"HIDKeyboardModifierMappingSrc": ${src}, "HIDKeyboardModifierMappingDst": ${dst}}'')) | ||
(lib.concatStringsSep ", ") | ||
]; | ||
}}" | ||
destination="/Library/LaunchDaemons/com.nix.remapkeys.${cfg.vendorID}-${cfg.productID}.plist" | ||
if [[ ! -L "$destination" ]]; then | ||
/usr/bin/sudo ${lib.getExe' pkgs.coreutils "ln"} -s "$source" "$destination" | ||
/usr/bin/sudo /bin/launchctl load -w "$destination" | ||
fi | ||
''; | ||
}; | ||
} |
This file contains 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