nix/nixos/keyd.nix
2025-12-24 20:08:10 -06:00

110 lines
2.6 KiB
Nix

{
config,
lib,
pkgs,
...
}:
{
options.custom = with lib; {
keyd = {
enable = mkEnableOption "Enable keyd";
ids = mkOption {
type = types.listOf types.str;
default = [ ];
example = [
"0001:0001:70533846"
"3434:06a0:d7dfbeabt"
"046d:c339:9f276ca6"
];
description = "List of keyboard is that will be configured";
};
};
};
config = lib.mkIf config.custom.keyd.enable {
environment.systemPackages = with pkgs; [
keyd
];
users.groups.keyd = { };
services.keyd =
let
commonSettings = {
main = {
capslock = "layer(capslock)";
insert = "S-insert";
};
meta = {
# NOTE: c, v, x are NOT remapped here - they're handled by terminal/app configs
# This preserves Ctrl+C = SIGINT in terminals (macOS behavior)
# # Undo/Redo/Save/Select All/Find
# z = "C-z";
# "shift+z" = "C-y";
# s = "C-s";
# a = "C-a";
# f = "C-f";
#
# # Tab/Window management
# w = "C-w";
# t = "C-t";
# n = "C-n";
# q = "A-F4";
# Text navigation (macOS-style)
left = "home";
right = "end";
up = "C-home";
down = "C-end";
backspace = "C-backspace";
# Other common shortcuts
r = "C-r";
p = "C-p";
o = "C-o";
l = "C-l";
"/" = "C-/";
};
"meta+shift" = {
left = "S-home";
right = "S-end";
up = "C-S-home";
down = "C-S-end";
};
"capslock:C" = { };
};
in
{
enable = true;
keyboards = {
default = {
ids = [ "*" ];
settings = commonSettings;
};
workstation = {
ids = config.custom.keyd.ids;
settings = lib.mkMerge [
commonSettings
{
main = {
leftalt = "layer(meta)";
leftmeta = "layer(alt)";
};
}
];
};
};
};
systemd.services.keyd.serviceConfig.CapabilityBoundingSet = [
"CAP_SETGID"
];
environment.etc."libinput/local-overrides.quirks".text = ''
[Serial Keyboards]
MatchUdevType=keyboard
MatchName=keyd virtual keyboard
AttrKeyboardIntegration=internal
'';
};
}