2024-04-03 13:10:46 +02:00
|
|
|
{ pkgs, config, lib, ... }:
|
2023-06-22 17:13:46 +02:00
|
|
|
|
2024-04-03 13:10:46 +02:00
|
|
|
let
|
2024-04-06 16:42:07 +02:00
|
|
|
inherit (lib) mkEnableOption mkIf getExe singleton;
|
|
|
|
inherit (pkgs) piper interception-tools;
|
|
|
|
inherit (pkgs.interception-tools-plugins) dual-function-keys;
|
2024-06-19 08:02:43 +02:00
|
|
|
inherit (cfg) mouseSettings disableLaptopKeyboard lidIgnore powerIgnore keyboardBinds bluetooth phone;
|
2024-04-09 15:19:29 +02:00
|
|
|
inherit (builtins) toJSON;
|
2024-04-06 16:42:07 +02:00
|
|
|
|
|
|
|
dualFunctionKeysConfig = "dual-function-keys.yaml";
|
2024-04-03 13:10:46 +02:00
|
|
|
|
|
|
|
cfg = config.modules.hardware;
|
|
|
|
in
|
2023-06-22 17:13:46 +02:00
|
|
|
{
|
2024-04-03 13:10:46 +02:00
|
|
|
options.modules.hardware = {
|
2024-04-06 16:42:07 +02:00
|
|
|
keyboardBinds = mkEnableOption "start button for rofi, caps lock as escape, etc.";
|
2024-04-04 06:25:01 +02:00
|
|
|
mouseSettings = mkEnableOption "piper for gaming mice";
|
2024-06-13 11:14:19 +02:00
|
|
|
bluetooth = mkEnableOption "bluetooth support";
|
2024-04-04 06:25:01 +02:00
|
|
|
disableLaptopKeyboard = mkEnableOption "udev rule to disable laptop keyboard";
|
|
|
|
lidIgnore = mkEnableOption "ignoring the laptop lid on close";
|
|
|
|
powerIgnore = mkEnableOption "ignoring the power button on press";
|
2024-06-19 08:02:43 +02:00
|
|
|
phone = mkEnableOption "Phone support";
|
2024-04-03 13:10:46 +02:00
|
|
|
};
|
|
|
|
|
2024-04-06 16:42:07 +02:00
|
|
|
config = {
|
2024-06-13 11:14:19 +02:00
|
|
|
hardware.bluetooth.enable = mkIf bluetooth true;
|
|
|
|
|
2024-04-04 06:25:01 +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
|
|
|
|
2024-04-04 06:25:01 +02:00
|
|
|
udev.extraRules = mkIf disableLaptopKeyboard ''
|
|
|
|
KERNEL=="event*", ATTRS{name}=="AT Translated Set 2 keyboard", ENV{LIBINPUT_IGNORE_DEVICE}="1"
|
|
|
|
'';
|
2024-04-03 12:29:04 +02:00
|
|
|
|
2024-04-04 06:25:01 +02:00
|
|
|
logind = {
|
|
|
|
lidSwitch = mkIf lidIgnore "ignore";
|
|
|
|
extraConfig = mkIf powerIgnore "HandlePowerKey=ignore";
|
2024-06-19 08:02:43 +02:00
|
|
|
powerKey = mkIf phone "suspend";
|
|
|
|
powerKeyLongPress = mkIf phone "poweroff";
|
2024-04-04 06:25:01 +02:00
|
|
|
};
|
2024-04-06 16:42:07 +02:00
|
|
|
|
|
|
|
interception-tools = {
|
|
|
|
enable = mkIf keyboardBinds true;
|
|
|
|
plugins = [ dual-function-keys ];
|
|
|
|
|
|
|
|
udevmonConfig = toJSON (singleton {
|
|
|
|
JOB = /* bash */ ''
|
|
|
|
${interception-tools}/bin/intercept -g $DEVNODE |
|
|
|
|
${getExe dual-function-keys} -c /etc/${dualFunctionKeysConfig} |
|
|
|
|
${interception-tools}/bin/uinput -d $DEVNODE
|
|
|
|
'';
|
|
|
|
|
|
|
|
DEVICE = {
|
|
|
|
EVENTS = {
|
|
|
|
EV_KEY = [ "KEY_CAPSLOCK" "KEY_ESC" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
2024-04-03 13:10:46 +02:00
|
|
|
};
|
2024-04-04 06:25:01 +02:00
|
|
|
|
|
|
|
environment.systemPackages = mkIf mouseSettings [ piper ];
|
2024-04-06 16:42:07 +02:00
|
|
|
|
|
|
|
environment.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";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
KEY = "KEY_SYSRQ";
|
|
|
|
TAP = "KEY_SYSRQ";
|
|
|
|
HOLD = "KEY_RIGHTMETA";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
KEY = "KEY_LEFTMETA";
|
|
|
|
TAP = [ "KEY_LEFTMETA" "KEY_F1" ];
|
|
|
|
HOLD = "KEY_LEFTMETA";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
KEY = "KEY_RIGHTSHIFT";
|
|
|
|
TAP = [ "KEY_LEFTMETA" "KEY_F2" ];
|
|
|
|
HOLD = "KEY_RIGHTSHIFT";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
KEY = "KEY_RIGHTALT";
|
|
|
|
TAP = "KEY_GRAVE";
|
|
|
|
HOLD = "KEY_RIGHTALT";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2024-04-03 13:10:46 +02:00
|
|
|
};
|
2023-05-17 17:51:52 +02:00
|
|
|
}
|