diff --git a/default.nix b/default.nix index 2b429339..d1ef5cee 100644 --- a/default.nix +++ b/default.nix @@ -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 diff --git a/modules/system/activation-scripts.nix b/modules/system/activation-scripts.nix index dcf4762e..43f20c22 100644 --- a/modules/system/activation-scripts.nix +++ b/modules/system/activation-scripts.nix @@ -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} diff --git a/modules/system/keyboard.nix b/modules/system/keyboard.nix new file mode 100644 index 00000000..3b16c3b1 --- /dev/null +++ b/modules/system/keyboard.nix @@ -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 + . + ''; + }; + }; + + 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 + ''; + + }; +}