From 6668f416bd56c628c4fdcf2c92710abf4ae69a36 Mon Sep 17 00:00:00 2001 From: punkfairie Date: Mon, 2 Dec 2024 18:52:06 -0800 Subject: [PATCH] feat(home): Install/configure kanata on non-NixOS systems --- homes/x86_64-linux/marley@nyx/default.nix | 11 +++--- modules/home/services/kanata/config.kbd | 30 ++++++++++++++++ modules/home/services/kanata/default.nix | 43 +++++++++++++++++++++++ 3 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 modules/home/services/kanata/config.kbd create mode 100644 modules/home/services/kanata/default.nix diff --git a/homes/x86_64-linux/marley@nyx/default.nix b/homes/x86_64-linux/marley@nyx/default.nix index 0de121e..f5bd56d 100644 --- a/homes/x86_64-linux/marley@nyx/default.nix +++ b/homes/x86_64-linux/marley@nyx/default.nix @@ -2,14 +2,12 @@ lib, pkgs, ... -}: -let +}: let inherit (lib.marleyos) enabled; -in -{ - imports = [ ./autorandr.nix ]; +in { + imports = [./autorandr.nix]; - home.keyboard.options = [ "apple:alupckeys" ]; + home.keyboard.options = ["apple:alupckeys"]; # FIXME: Remove once we are on NixOS targets.genericLinux = enabled; @@ -72,6 +70,7 @@ in }; services = { clipboard = enabled; + kanata = enabled; syncthing = enabled; }; xorg = { diff --git a/modules/home/services/kanata/config.kbd b/modules/home/services/kanata/config.kbd new file mode 100644 index 0000000..54bbf69 --- /dev/null +++ b/modules/home/services/kanata/config.kbd @@ -0,0 +1,30 @@ +;; vim: ft=commonlisp + +(defcfg + process-unmapped-keys yes +) + +(defsrc + caps a s d f j k l ; +) + +(defvar + tap-time 150 + hold-time 200 +) + +(defalias + escctrl (tap-hold 100 100 esc caps) + a (tap-hold $tap-time $hold-time a lmet) + s (tap-hold $tap-time $hold-time s lalt) + d (tap-hold $tap-time $hold-time d lsft) + f (tap-hold $tap-time $hold-time f lctl) + j (tap-hold $tap-time $hold-time j rctl) + k (tap-hold $tap-time $hold-time k rsft) + l (tap-hold $tap-time $hold-time l ralt) + ; (tap-hold $tap-time $hold-time ; rmet) +) + +(deflayer base + @escctrl @a @s @d @f @j @k @l @; +) diff --git a/modules/home/services/kanata/default.nix b/modules/home/services/kanata/default.nix new file mode 100644 index 0000000..f4ae9af --- /dev/null +++ b/modules/home/services/kanata/default.nix @@ -0,0 +1,43 @@ +{ + lib, + config, + pkgs, + system, + ... +}: let + inherit (lib) mkEnableOption mkIf getExe; + inherit (lib.snowfall.system) is-darwin; + + cfg = config.marleyos.services.kanata; + isGenericLinux = config.targets.genericLinux.enable; + isNotNixOS = isGenericLinux || (is-darwin system); +in { + options.marleyos.services.kanata.enable = mkEnableOption "kanata"; + + # Kanata is available as a module for nixOS and that should be preferred when + # possible. + config = mkIf (cfg.enable && isNotNixOS) { + home.packages = with pkgs; [ + kanata + ]; + + systemd.user.services.kanata = { + Unit = { + Description = "Kanata keyboard remapper"; + Documentation = "https://github.com/jtroo/kanata"; + }; + + Service = { + Environment = [ + "PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin" + "DISPLAY=:0" + ]; + Type = "simple"; + ExecStart = "/bin/sh -c 'exec ${getExe pkgs.kanata} --cfg ${./config.kbd}'"; + Restart = "no"; + }; + + Install.WantedBy = ["default.target"]; + }; + }; +}