2018-01-08 21:01:44 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.system.keyboard;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
system.keyboard.enableKeyMapping = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-14 21:02:32 +00:00
|
|
|
description = "Whether to enable keyboard mappings.";
|
2018-01-08 21:01:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
system.keyboard.remapCapsLockToControl = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-14 21:02:32 +00:00
|
|
|
description = "Whether to remap the Caps Lock key to Control.";
|
2018-01-08 21:01:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
system.keyboard.remapCapsLockToEscape = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-14 21:02:32 +00:00
|
|
|
description = "Whether to remap the Caps Lock key to Escape.";
|
2018-01-08 21:01:44 +00:00
|
|
|
};
|
|
|
|
|
2018-01-10 18:48:04 +00:00
|
|
|
system.keyboard.nonUS.remapTilde = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-14 21:02:32 +00:00
|
|
|
description = "Whether to remap the Tilde key on non-us keyboards.";
|
2018-01-10 18:48:04 +00:00
|
|
|
};
|
|
|
|
|
2020-10-23 14:47:38 +00:00
|
|
|
system.keyboard.swapLeftCommandAndLeftAlt = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-14 21:02:32 +00:00
|
|
|
description = "Whether to swap the left Command key and left Alt key.";
|
2020-10-23 14:47:38 +00:00
|
|
|
};
|
|
|
|
|
2024-07-02 12:22:37 +00:00
|
|
|
system.keyboard.swapLeftCtrlAndFn = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to swap the left Control key and Fn (Globe) key.";
|
|
|
|
};
|
|
|
|
|
2018-01-08 21:01:44 +00:00
|
|
|
system.keyboard.userKeyMapping = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.listOf (types.attrsOf types.int);
|
|
|
|
default = [];
|
2024-04-14 21:02:32 +00:00
|
|
|
description = ''
|
2018-01-08 21:01:44 +00:00
|
|
|
List of keyboard mappings to apply, for more information see
|
2023-06-22 11:21:32 +00:00
|
|
|
<https://developer.apple.com/library/content/technotes/tn2450/_index.html>.
|
2018-01-08 21:01:44 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
2018-01-08 21:04:32 +00:00
|
|
|
warnings = mkIf (!cfg.enableKeyMapping && cfg.userKeyMapping != [])
|
|
|
|
[ "system.keyboard.enableKeyMapping is not enabled, keyboard mappings will not be configured." ];
|
|
|
|
|
2018-01-10 18:48:04 +00:00
|
|
|
system.keyboard.userKeyMapping = [
|
|
|
|
(mkIf cfg.remapCapsLockToControl { HIDKeyboardModifierMappingSrc = 30064771129; HIDKeyboardModifierMappingDst = 30064771296; })
|
|
|
|
(mkIf cfg.remapCapsLockToEscape { HIDKeyboardModifierMappingSrc = 30064771129; HIDKeyboardModifierMappingDst = 30064771113; })
|
|
|
|
(mkIf cfg.nonUS.remapTilde { HIDKeyboardModifierMappingSrc = 30064771172; HIDKeyboardModifierMappingDst = 30064771125; })
|
2020-10-23 14:47:38 +00:00
|
|
|
(mkIf cfg.swapLeftCommandAndLeftAlt {
|
|
|
|
HIDKeyboardModifierMappingSrc = 30064771299;
|
|
|
|
HIDKeyboardModifierMappingDst = 30064771298;
|
|
|
|
})
|
|
|
|
(mkIf cfg.swapLeftCommandAndLeftAlt {
|
|
|
|
HIDKeyboardModifierMappingSrc = 30064771298;
|
|
|
|
HIDKeyboardModifierMappingDst = 30064771299;
|
|
|
|
})
|
2024-07-02 12:22:37 +00:00
|
|
|
(mkIf cfg.swapLeftCtrlAndFn {
|
|
|
|
HIDKeyboardModifierMappingSrc = 30064771296;
|
|
|
|
HIDKeyboardModifierMappingDst = 1095216660483;
|
|
|
|
})
|
|
|
|
(mkIf cfg.swapLeftCtrlAndFn {
|
|
|
|
HIDKeyboardModifierMappingSrc = 1095216660483;
|
|
|
|
HIDKeyboardModifierMappingDst = 30064771296;
|
|
|
|
})
|
2018-01-08 21:01:44 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
system.activationScripts.keyboard.text = optionalString cfg.enableKeyMapping ''
|
|
|
|
# Configuring keyboard
|
|
|
|
echo "configuring keyboard..." >&2
|
|
|
|
hidutil property --set '{"UserKeyMapping":${builtins.toJSON cfg.userKeyMapping}}' > /dev/null
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|