1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00

keyboard: add options for keyboard mappings

Fixes #55
This commit is contained in:
Daiderd Jordan 2018-01-08 22:01:44 +01:00
parent 3bedff357a
commit edc3be51ce
No known key found for this signature in database
GPG key ID: D02435D05B810C96
3 changed files with 58 additions and 2 deletions

View file

@ -22,15 +22,16 @@ let
./modules/system
./modules/system/activation-checks.nix
./modules/system/activation-scripts.nix
./modules/system/applications.nix
./modules/system/defaults-write.nix
./modules/system/defaults/NSGlobalDomain.nix
./modules/system/defaults/LaunchServices.nix
./modules/system/defaults/NSGlobalDomain.nix
./modules/system/defaults/dock.nix
./modules/system/defaults/finder.nix
./modules/system/defaults/smb.nix
./modules/system/defaults/trackpad.nix
./modules/system/applications.nix
./modules/system/etc.nix
./modules/system/keyboard.nix
./modules/system/launchd.nix
./modules/system/shells.nix
./modules/system/version.nix

View file

@ -59,6 +59,7 @@ in
${cfg.activationScripts.nix-daemon.text}
${cfg.activationScripts.time.text}
${cfg.activationScripts.networking.text}
${cfg.activationScripts.keyboard.text}
${cfg.activationScripts.extraPostActivation.text}

View file

@ -0,0 +1,54 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.system.keyboard;
in
{
options = {
system.keyboard.enableKeyMapping = mkOption {
type = types.bool;
default = false;
description = "Whether to enable keyboard mappings.";
};
system.keyboard.remapCapsLockToControl = mkOption {
type = types.bool;
default = false;
description = "Whether to remap the Caps Lock key to Control.";
};
system.keyboard.remapCapsLockToEscape = mkOption {
type = types.bool;
default = false;
description = "Whether to remap the Caps Lock key to Escape.";
};
system.keyboard.userKeyMapping = mkOption {
internal = true;
type = types.listOf (types.attrsOf types.int);
default = [];
description = ''
List of keyboard mappings to apply, for more information see
<link xlink:href="https://developer.apple.com/library/content/technotes/tn2450/_index.html"/>.
'';
};
};
config = {
system.keyboard.userKeyMapping = mkMerge [
(mkIf cfg.remapCapsLockToControl [{ HIDKeyboardModifierMappingSrc = 30064771129; HIDKeyboardModifierMappingDst = 30064771296; }])
(mkIf cfg.remapCapsLockToEscape [{ HIDKeyboardModifierMappingSrc = 30064771129; HIDKeyboardModifierMappingDst = 30064771113; }])
];
system.activationScripts.keyboard.text = optionalString cfg.enableKeyMapping ''
# Configuring keyboard
echo "configuring keyboard..." >&2
hidutil property --set '{"UserKeyMapping":${builtins.toJSON cfg.userKeyMapping}}' > /dev/null
'';
};
}