mirror of
https://forge.katzen.cafe/schrottkatze/nix-configs.git
synced 2024-11-05 15:16:23 +01:00
add input remapping module with easier configuration
This commit is contained in:
parent
01d070eb40
commit
991cc8fc88
|
@ -26,7 +26,22 @@
|
|||
social.enable = true;
|
||||
mail.enable = true;
|
||||
gaming.enable = true;
|
||||
evremap.enable = true;
|
||||
};
|
||||
input.remapping = {
|
||||
enable = true;
|
||||
devices."AT Translated Set 2 keyboard" = {
|
||||
swapKeys = [
|
||||
["KEY_Y" "KEY_Z"]
|
||||
["KEY_LEFTALT" "KEY_LEFTMETA"]
|
||||
];
|
||||
dual_role = [
|
||||
{
|
||||
input = "KEY_CAPSLOCK";
|
||||
hold = ["KEY_LEFTCTRL"];
|
||||
tap = ["KEY_ESC"];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
terminal.enable = true;
|
||||
};
|
||||
|
|
|
@ -30,10 +30,11 @@ in
|
|||
./social.nix
|
||||
./mail.nix
|
||||
./specific-hardware
|
||||
./evremap.nix
|
||||
./xmonad.nix
|
||||
./fonts.nix
|
||||
./firefox.nix
|
||||
./x.nix
|
||||
./input
|
||||
];
|
||||
|
||||
i18n.inputMethod = {
|
||||
|
@ -52,32 +53,6 @@ in
|
|||
services = {
|
||||
printing.enable = true;
|
||||
gnome.gnome-keyring.enable = true;
|
||||
|
||||
xserver = {
|
||||
enable = true;
|
||||
|
||||
xkb = {
|
||||
layout = "us";
|
||||
variant = "altgr-intl";
|
||||
};
|
||||
|
||||
libinput = {
|
||||
enable = true;
|
||||
};
|
||||
|
||||
desktopManager = {
|
||||
xterm.enable = false;
|
||||
};
|
||||
|
||||
displayManager = {
|
||||
defaultSession = "none+xmonad";
|
||||
gdm.enable = true;
|
||||
};
|
||||
|
||||
windowManager.xmonad = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
programs.xss-lock = {
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
cfg = config.jade.desktop.evremap;
|
||||
evremap = pkgs.rustPlatform.buildRustPackage {
|
||||
pname = "evremap";
|
||||
version = "0.1.0";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "wez";
|
||||
repo = "evremap";
|
||||
rev = "4480c4eda223b98899b0fbd926bc34f7bd0e1a18";
|
||||
sha256 = "sha256-BxSrphgW1n465FX6bKVkq6O0XE2JqanfSYlsGwWUWkQ=";
|
||||
};
|
||||
cargoHash = "";
|
||||
cargoLock.lockFile = ../../other/evremap.Cargo.lock;
|
||||
postPatch = ''
|
||||
cp ${../../other/evremap.Cargo.lock} Cargo.lock
|
||||
'';
|
||||
nativeBuildInputs = [pkgs.pkg-config];
|
||||
buildInputs = [pkgs.libevdev];
|
||||
};
|
||||
in
|
||||
with lib; {
|
||||
options.jade.desktop.evremap = {
|
||||
enable = mkEnableOption "Enable evremap";
|
||||
};
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services.evremap = {
|
||||
script = "${evremap}/bin/evremap remap ${../../other/remaps-${config.networking.hostName}.toml}";
|
||||
wantedBy = ["multi-user.target"];
|
||||
unitConfig = {
|
||||
Restart = "on-failure";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
15
modules/desktop/input/default.nix
Normal file
15
modules/desktop/input/default.nix
Normal file
|
@ -0,0 +1,15 @@
|
|||
{...}: {
|
||||
imports = [
|
||||
./evremap.nix
|
||||
];
|
||||
services.xserver = {
|
||||
xkb = {
|
||||
layout = "us";
|
||||
variant = "altgr-intl";
|
||||
};
|
||||
|
||||
libinput = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
}
|
110
modules/desktop/input/evremap.nix
Normal file
110
modules/desktop/input/evremap.nix
Normal file
|
@ -0,0 +1,110 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
utils,
|
||||
...
|
||||
}: let
|
||||
cfg = config.jade.input.remapping;
|
||||
evremap = pkgs.rustPlatform.buildRustPackage {
|
||||
pname = "evremap";
|
||||
version = "0.1.0";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "wez";
|
||||
repo = "evremap";
|
||||
rev = "4480c4eda223b98899b0fbd926bc34f7bd0e1a18";
|
||||
sha256 = "sha256-BxSrphgW1n465FX6bKVkq6O0XE2JqanfSYlsGwWUWkQ=";
|
||||
};
|
||||
cargoHash = "";
|
||||
cargoLock.lockFile = ../../../other/evremap.Cargo.lock;
|
||||
postPatch = ''
|
||||
cp ${../../../other/evremap.Cargo.lock} Cargo.lock
|
||||
'';
|
||||
nativeBuildInputs = [pkgs.pkg-config];
|
||||
buildInputs = [pkgs.libevdev];
|
||||
};
|
||||
toml = pkgs.formats.toml {};
|
||||
in
|
||||
with lib; {
|
||||
options.jade.input.remapping = {
|
||||
enable = mkEnableOption "Enable evremap";
|
||||
devices = mkOption {
|
||||
type = types.attrsOf (types.submodule ({name, ...}: {
|
||||
options = {
|
||||
device_name = mkOption {
|
||||
type = types.str;
|
||||
description = "The device name";
|
||||
default = name;
|
||||
};
|
||||
remap = mkOption {
|
||||
type = types.listOf (types.submodule ({...}: {
|
||||
options.input = mkOption {type = types.listOf types.str;};
|
||||
options.output = mkOption {type = types.listOf types.str;};
|
||||
}));
|
||||
default = [];
|
||||
};
|
||||
swapKeys = mkOption {
|
||||
description = "Lists with two keys to be swapped on the keyboard layout.";
|
||||
type = types.listOf (
|
||||
# verify that each key swapping list contains two elements
|
||||
types.addCheck (types.listOf types.str) (v: builtins.length v == 2)
|
||||
);
|
||||
default = [];
|
||||
};
|
||||
dual_role = mkOption {
|
||||
type = types.listOf (types.submodule ({...}: {
|
||||
options.input = mkOption {type = types.str;};
|
||||
options.hold = mkOption {type = types.listOf types.str;};
|
||||
options.tap = mkOption {type = types.listOf types.str;};
|
||||
}));
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
}));
|
||||
};
|
||||
};
|
||||
config = mkIf cfg.enable (
|
||||
with builtins; let
|
||||
devs = map ({
|
||||
device_name,
|
||||
remap,
|
||||
swapKeys,
|
||||
dual_role,
|
||||
}: {
|
||||
inherit device_name dual_role;
|
||||
|
||||
# expand swapKeys to normal remaps
|
||||
remap = concatLists [
|
||||
remap
|
||||
(lib.lists.flatten (map (keys: [
|
||||
{
|
||||
input = [(head keys)];
|
||||
output = [(lib.lists.last keys)];
|
||||
}
|
||||
{
|
||||
input = [(lib.lists.last keys)];
|
||||
output = [(head keys)];
|
||||
}
|
||||
])
|
||||
swapKeys))
|
||||
];
|
||||
}) (attrValues cfg.devices);
|
||||
in {
|
||||
# generate numbered systemd services for each device to be remapped
|
||||
# https://github.com/wez/evremap/issues/17
|
||||
systemd.services = listToAttrs (genList (i: {
|
||||
name = "evremap${toString i}";
|
||||
value = let
|
||||
cfgFile = toml.generate "remaps-${toString i}.toml" (elemAt devs i);
|
||||
in {
|
||||
script = "${evremap}/bin/evremap remap ${cfgFile}";
|
||||
wantedBy = ["multi-user.target"];
|
||||
unitConfig = {
|
||||
Restart = "on-failure";
|
||||
};
|
||||
};
|
||||
}) (length devs));
|
||||
environment.systemPackages = [evremap];
|
||||
}
|
||||
);
|
||||
}
|
18
modules/desktop/x.nix
Normal file
18
modules/desktop/x.nix
Normal file
|
@ -0,0 +1,18 @@
|
|||
{...}: {
|
||||
services.xserver = {
|
||||
enable = true;
|
||||
|
||||
desktopManager = {
|
||||
xterm.enable = false;
|
||||
};
|
||||
|
||||
displayManager = {
|
||||
defaultSession = "none+xmonad";
|
||||
gdm.enable = true;
|
||||
};
|
||||
|
||||
windowManager.xmonad = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
device_name = "AT Translated Set 2 keyboard"
|
||||
|
||||
[[remap]]
|
||||
input = [ "KEY_Y" ]
|
||||
output = [ "KEY_Z" ]
|
||||
|
||||
[[remap]]
|
||||
input = [ "KEY_Z" ]
|
||||
output = [ "KEY_Y" ]
|
||||
|
||||
[[remap]]
|
||||
input = [ "KEY_LEFTALT" ]
|
||||
output = [ "KEY_LEFTMETA" ]
|
||||
|
||||
[[remap]]
|
||||
input = [ "KEY_LEFTMETA" ]
|
||||
output = [ "KEY_LEFTALT" ]
|
||||
|
||||
[[dual_role]]
|
||||
input = "KEY_CAPSLOCK"
|
||||
hold = ["KEY_LEFTCTRL"]
|
||||
tap = ["KEY_ESC"]
|
Loading…
Reference in a new issue