nix-config/modules/hardware.nix

96 lines
2.1 KiB
Nix
Raw Normal View History

2024-08-03 20:40:07 +02:00
{
pkgs,
config,
lib,
...
}:
2023-06-22 17:13:46 +02:00
let
inherit (pkgs) piper interception-tools;
inherit (pkgs.interception-tools-plugins) dual-function-keys;
2024-04-09 15:19:29 +02:00
inherit (builtins) toJSON;
2024-08-03 20:40:07 +02:00
inherit (lib)
mkEnableOption
mkIf
getExe
singleton
;
inherit (cfg)
mouseSettings
lidIgnore
keyboardBinds
bluetooth
;
dualFunctionKeysConfig = "dual-function-keys.yaml";
cfg = config.modules.hardware;
in
2023-06-22 17:13:46 +02:00
{
options.modules.hardware = {
keyboardBinds = mkEnableOption "caps lock as ctrl when held and esc when tapped";
mouseSettings = mkEnableOption "piper for gaming mice";
2024-06-13 11:14:19 +02:00
bluetooth = mkEnableOption "bluetooth support";
lidIgnore = mkEnableOption "ignoring the laptop lid on close";
};
config = {
hardware.bluetooth.enable = mkIf bluetooth true;
2024-06-13 11:14:19 +02:00
services = {
ratbagd.enable = mkIf mouseSettings true;
2024-06-13 11:14:19 +02:00
blueman.enable = mkIf bluetooth true;
2023-05-17 17:51:52 +02:00
logind = {
lidSwitch = mkIf lidIgnore "ignore";
2024-07-23 21:37:24 +02:00
extraConfig = "HandlePowerKey=suspend";
};
interception-tools = {
enable = mkIf keyboardBinds true;
plugins = [ dual-function-keys ];
udevmonConfig = toJSON (singleton {
2024-08-03 20:40:07 +02:00
JOB = # bash
''
${interception-tools}/bin/intercept -g $DEVNODE |
${getExe dual-function-keys} -c /etc/${dualFunctionKeysConfig} |
${interception-tools}/bin/uinput -d $DEVNODE
'';
DEVICE = {
EVENTS = {
2024-08-03 20:40:07 +02:00
EV_KEY = [
"KEY_CAPSLOCK"
"KEY_ESC"
];
};
};
});
};
};
environment = {
systemPackages = mkIf mouseSettings [ piper ];
etc.${dualFunctionKeysConfig}.text = toJSON {
TIMING = [
{ TAP_MILLISEC = 1000; }
{ DOUBLE_TAP_MILLISEC = 0; }
{ SYNTHETIC_KEYS_PAUSE_MILLISEC = 0; }
];
MAPPINGS = [
{
KEY = "KEY_CAPSLOCK";
TAP = "KEY_ESC";
HOLD = "KEY_LEFTCTRL";
}
];
};
};
};
2023-05-17 17:51:52 +02:00
}