From 6315fec2e903863b082891390eae57620d47e187 Mon Sep 17 00:00:00 2001 From: Jonas Hahn Date: Thu, 20 Nov 2025 21:01:54 +0100 Subject: [PATCH] Have kmonad as a seperate service not managed by nixos --- flake.nix | 5 - hosts/minoxy-workstation/configuration.nix | 2 - hosts/nixyos-asus/configuration.nix | 1 - hosts/thinix-thinkpad/configuration.nix | 1 - modules/hardware/config.kbd | 206 +++++++++++++++++++++ modules/hardware/xremap.nix | 15 -- user/packages.nix | 1 + 7 files changed, 207 insertions(+), 24 deletions(-) delete mode 100644 modules/hardware/xremap.nix diff --git a/flake.nix b/flake.nix index d428b7c..1380eae 100644 --- a/flake.nix +++ b/flake.nix @@ -14,10 +14,6 @@ url = "github:nix-community/home-manager/release-25.05"; inputs.nixpkgs.follows = "nixpkgs"; }; - kmonad = { - url = "github:kmonad/kmonad?dir=nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; # Understand what everything does @@ -32,7 +28,6 @@ helperModules = [ ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; }) - kmonad.nixosModules.default home-manager.nixosModules.home-manager { home-manager.useGlobalPkgs = true; diff --git a/hosts/minoxy-workstation/configuration.nix b/hosts/minoxy-workstation/configuration.nix index 8777f7d..ccb3855 100644 --- a/hosts/minoxy-workstation/configuration.nix +++ b/hosts/minoxy-workstation/configuration.nix @@ -14,7 +14,6 @@ ./../../modules/hardware/nvidia.nix ./../../modules/hardware/boot.nix - ./../../modules/hardware/xremap.nix ]; networking.hostName = "minoxy"; @@ -30,7 +29,6 @@ SUBSYSTEM=="block", ENV{ID_FS_UUID}=="A09C8D5E9C8D2FB8", ENV{UDISKS_IGNORE}="1" ''; - # TODO: Make all your working systems go to ext4 on the full disk for ease of use and storage virtualisation.docker.storageDriver = "btrfs"; diff --git a/hosts/nixyos-asus/configuration.nix b/hosts/nixyos-asus/configuration.nix index 8d75e52..bbaf4ab 100644 --- a/hosts/nixyos-asus/configuration.nix +++ b/hosts/nixyos-asus/configuration.nix @@ -9,7 +9,6 @@ ./../../modules/essential.nix ./../../modules/common/sops.nix - ./../../modules/hardware/xremap.nix ./../../modules/hardware/boot.nix ./../../modules/laptop/powersave.nix diff --git a/hosts/thinix-thinkpad/configuration.nix b/hosts/thinix-thinkpad/configuration.nix index a9b1169..c3e36f3 100644 --- a/hosts/thinix-thinkpad/configuration.nix +++ b/hosts/thinix-thinkpad/configuration.nix @@ -9,7 +9,6 @@ ./../../modules/essential.nix ./../../modules/common/sops.nix - ./../../modules/hardware/xremap.nix ./../../modules/hardware/boot.nix ./../../modules/graphics/workstation.nix diff --git a/modules/hardware/config.kbd b/modules/hardware/config.kbd index e69de29..12a1e7b 100644 --- a/modules/hardware/config.kbd +++ b/modules/hardware/config.kbd @@ -0,0 +1,206 @@ +(defcfg + ;; For Linux + input (device-file "/dev/input/by-id/usb-04d9_daskeyboard-event-kbd" :ignore-missing true) + output (uinput-sink "My KMonad output" + ;; To understand the importance of the following line, see the section on + ;; Compose-key sequences at the near-bottom of this file. + "sleep 1 && setxkbmap -option compose:ralt") + cmp-seq ralt ;; Set the compose key to `RightAlt' + cmp-seq-delay 5 ;; 5ms delay between each compose-key sequence press + key-seq-delay 5 ;; 5ms delay between each outputted key event + + ;; For Windows + ;; input (low-level-hook) + ;; output (send-event-sink) + + ;; For MacOS + ;; input (iokit-name "my-keyboard-product-string") + ;; output (kext) + + ;; Comment this if you want unhandled events not to be emitted + fallthrough true + + ;; Set this to false to disable any command-execution in KMonad + allow-cmd true + + ;; Set the implicit around to `around` + implicit-around around +) + + +#| -------------------------------------------------------------------------- + Necessary: at least 1 `defsrc` block + + It is difficult to explain the `defsrc` block without immediately going into + `deflayer` blocks as well. Essentially, KMonad maps input-events to various + internal actions, many of which generate output events. The `defsrc` block + explains the layout on which we specify our `deflayer`s down the line. + + It is important to realize that the `defsrc` block doesn't *necessarily* have + to coincide with your actual input keyboard. You can specify a full 100% + `defsrc` block, but only use a 40% keyboard. This will mean that every + `deflayer` you specify will also have to match your 100% `defsrc`, and that + your actual keyboard would be physically unable to trigger about 60% of your + keymap, but it would be perfectly valid syntax. + + The dual of this (and more useful) is that it is also perfectly valid to only + specify that part of your keyboard in `defsrc` that you want to remap. If you + use a 100% keyboard, but don't want to remap the numpad at all you can simply + leave the numpad out of your `defsrc`, and it should work just fine. In that + particular case you probably want to set `fallthrough` to `true` in your + `defcfg` block though. + + There is also support for named `defsrc` blocks. They contain `:name ` + as the first argument in their definition. + + The layouting in the `defsrc` block is completely free, whitespace simply gets + ignored. We strive to provide a name for every keycode that is no longer than + 4 characters, so we find that laying out your keymap in columns of 5 works out + quite nicely (although wider columns will allow for more informative aliases, + see below). + + You can also insert a placeholder button using `XX`. This is almost the same + as extra white space but you still need to bind a button to it. Said button is + never used. This is occasionally useful if you have buttons which don't emit a + keycode or have the same keycode multiple times on the same keyboard. In such + cases large chunks of whitespace may be more confusing then a placeholder + button. If you further want to specify which button this placeholder refers + to, you can use an alias (see below). + + Instead of keycodes directly you can also use an alias (see `defalias`). + The syntax for aliases is the same as described in `deflayer`. Keep in mind + that buttons, which won't work if you place them in `defsrc` directly, will + also not work if you use them via an alias. + + Most keycodes should be obvious. If you are unsure, check + './src/KMonad/Keyboard/Keycode.hs'. Every Keycode has a name corresponding to + its Keycode name, but all lower-case and with the 'Key' prefix removed. There + are also various aliases for Keycodes starting around line 350. If you are + trying to bind a key and there is not a 4-letter alias, please file an issue, + or better yet, a pull-request, and it will be added promptly. + + Also, you can consult './keymap/template/' for various input templates to use + directly or to look up keycodes by position. Here we use the input-template + for 'us_ansi_60.kbd' + + -------------------------------------------------------------------------- |# + +(defsrc + grv 1 2 3 4 5 6 7 8 9 0 - = bspc + tab q w e r t y u i o p [ ] \ + caps a s d f g h j k l ; ' ret + lsft z x c v b n m , . / rsft + lctl lmet lalt spc ralt rmet cmp rctl +) + +(deflayer capsasa + grv 1 2 3 4 5 6 7 8 9 0 - = bspc + tab q w e r t y u i o p [ ] \ + lctrl a s d f g h j k l ; ' ret + lsft z x c v b n m , . / rsft + lctl lmet lalt spc ralt rmet cmp rctl +) + +(defsrc :name numpad + nlck kp/ kp* kp- + kp7 kp8 kp9 kp+ + kp4 kp5 kp6 + kp1 kp2 kp3 kprt + kp0 kp. +) + +(defsrc :name with-aliases @foo @power) + + + +(defalias + num (layer-toggle numbers) ;; Bind num to a button that switches to a layer + kil C-A-del ;; Bind kil to a button that Ctrl-Alt-deletes + power XX ;; Placeholder for power button of keyboard + foo @bar ;; An alias with a forward reference to another alias + bar a +) + + +#| NOTE: The above code could just as easily have been written as: +(defalias num (layer-toggle numbers)) +(defalias kil C-A-del) + +(deflayer qwerty + grv 1 2 3 4 5 6 7 8 9 0 - = bspc + tab q w e r t y u i o p [ ] \ + caps a s d f g h j k l ; ' ret + lsft z x c v b n m , . / rsft + lctl @num lalt spc ralt rmet @sym @tst +) + +(deflayer phone :source numpad + :implicit-around disabled + nlck kp/ kp* kp- + kp1 kp2 kp3 kp+ + kp4 kp5 kp6 + kp7 kp8 kp9 kprt + kp0 kp. +) + + + +(deflayer numbers + _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ XX / 7 8 9 - _ _ _ + _ _ _ _ _ XX * 4 5 6 + _ _ + _ _ \( \) . XX 0 1 2 3 _ _ + _ _ _ _ _ _ _ _ +) + + + +(defalias + + ;; Something useful + cpy C-c + pst C-v + cut C-x + + ;; Something silly + md1 (around a (around b c)) ;; abc + md2 (around a (around-only lsft b)) ;; aB + md3 C-A-M-S-l + md4 (around % b) ;; BEWARE: %B, not %b, do you see why? + md5 (around-when-alone lctl c) +) + + +(defalias + ctl-lck (stepped (press-only lctl) (release-only lctl))) + + + +(deflayer modded-test + _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ @md4 _ _ _ _ _ _ _ _ _ _ _ + _ _ @md1 @md2 @md3 _ _ _ _ _ _ _ _ + _ _ @cut @cpy @pst _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ +) + + +(defalias + mc1 #(K M o n a d) + mc2 #(C-c P50 A-tab P50 C-v) ;; Careful, this might do something + mc3 #(P200 h P150 4 P100 > < P50 > < P20 0 r z 1 ! 1 ! !) + mc4 (tap-macro a (pause 50) @md2 (pause 50) c) + mc5 (tap-macro-release esc esc esc) + mc6 #(@mc3 spc @mc3 spc @mc3) +) + +(deflayer macro-test + _ @mc1 @mc2 @mc3 @mc4 @mc5 @mc6 _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ +) + + + diff --git a/modules/hardware/xremap.nix b/modules/hardware/xremap.nix deleted file mode 100644 index 348786b..0000000 --- a/modules/hardware/xremap.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ inputs, ... }: - -{ - imports = [ inputs.kmonad.nixosModules.default ]; - - services.kmonad = { - enable = true; - keyboards = { - myKMonadOutput = { - device = "/dev/input/by-id/usb-HyperX_Alloy_Elite_RGB_HyperX_Alloy_Elite_RGB-event-kbd"; - config = builtins.readFile ./config.kbd; - }; - }; - }; -} diff --git a/user/packages.nix b/user/packages.nix index 6351522..28b10aa 100644 --- a/user/packages.nix +++ b/user/packages.nix @@ -115,6 +115,7 @@ bitwarden-cli lazydocker poppler_utils + unstable.kmonad prismlauncher entr yq