{ config, lib, pkgs, ... }: let cfg = config.module.keyd; in { config = lib.mkIf cfg.enable { environment.systemPackages = with pkgs; [ keyd ]; services.keyd = { enable = true; keyboards.default = { ids = [ "*" ]; settings = { # NOTE: Use `wev` to find key names. main = { backspace = "delete"; # Delete key on backspace. capslock = "overload(control, esc)"; # Ctrl/esc combo. compose = "layer(layer_compose)"; delete = "backslash"; esc = "timeout(grave, 150, print)"; # System controls. leftcontrol = "overload(layer_alternative, leftcontrol)"; # Alternative layer for home, end etc. rightcontrol = "layer(layer_number)"; # Media and other controls. rightshift = "backspace"; # Backspace. }; # Alternative navigation. layer_alternative = { # Fx keys. "0" = "f10"; "1" = "f1"; "2" = "f2"; "3" = "f3"; "4" = "f4"; "5" = "f5"; "6" = "f6"; "7" = "f7"; "8" = "f8"; "9" = "f9"; minus = "f11"; equal = "f12"; # Legacy navigation. a = "home"; d = "end"; p = "pageup"; n = "pagedown"; h = "left"; j = "down"; k = "up"; l = "right"; # Media controls. s = "volumedown"; w = "volumeup"; q = "previoussong"; e = "nextsong"; space = "playpause"; z = "micmute"; x = "stopcd"; c = "mute"; v = "ejectcd"; # Toggle audio output. # Reset keys. backspace = "backspace"; capslock = "capslock"; compose = "compose"; delete = "delete"; esc = "esc"; rightcontrol = "rightcontrol"; rightshift = "rightshift"; }; # Vacant compose key layer. layer_compose = { a = "a"; }; # Number inputs. layer_number = { "1" = "kpequal"; "2" = "kpslash"; "3" = "kpasterisk"; "4" = "kpminus"; a = "4"; c = "3"; d = "6"; e = "9"; f = "kpenter"; q = "7"; r = "kpplus"; s = "5"; v = "kpcomma"; w = "8"; x = "2"; z = "1"; shift = "backspace"; space = "0"; }; }; }; }; # HACK: Workaround for https://github.com/NixOS/nixpkgs/issues/290161 users.groups.keyd = { }; systemd.services.keyd.serviceConfig.CapabilityBoundingSet = [ "CAP_SETGID" ]; # Debug toggle just in case I need it again. # systemd.services.keyd.environment.KEYD_DEBUG = "1"; }; }