aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-11-16 17:46:54 +0530
committerAkshay Nair <phenax5@gmail.com>2024-11-16 17:47:42 +0530
commit459d83c13b4f903cc425a4c626fd66b1f27317aa (patch)
tree412b42fac2e57543dec238f0d3523689ab6b12c9 /modules
parent9434f518f49c72358835500889dbaecad034632d (diff)
downloadnixos-config-459d83c13b4f903cc425a4c626fd66b1f27317aa.tar.gz
nixos-config-459d83c13b4f903cc425a4c626fd66b1f27317aa.zip
Switch to upstream kmonad module
Diffstat (limited to '')
-rw-r--r--modules/keyboard/default.nix3
-rw-r--r--modules/keyboard/kmonad-nixos-module.nix187
-rw-r--r--modules/keyboard/kmonad.nix32
3 files changed, 2 insertions, 220 deletions
diff --git a/modules/keyboard/default.nix b/modules/keyboard/default.nix
index 6d68e0c..81e3c91 100644
--- a/modules/keyboard/default.nix
+++ b/modules/keyboard/default.nix
@@ -1,11 +1,12 @@
{ ... }:
{
- imports = [ ./kmonad.nix ];
+ # imports = [ ./kmonad.nix ];
services.kmonad = {
enable = true;
keyboards = {
k2 = {
+ name = "k2";
device = "/dev/input/by-id/usb-Keychron_Keychron_K2-event-kbd";
defcfg = {
enable = true;
diff --git a/modules/keyboard/kmonad-nixos-module.nix b/modules/keyboard/kmonad-nixos-module.nix
deleted file mode 100644
index 5f6cd34..0000000
--- a/modules/keyboard/kmonad-nixos-module.nix
+++ /dev/null
@@ -1,187 +0,0 @@
-{ config, lib, pkgs, ... }:
-
-let
- cfg = config.services.kmonad;
-
- # Per-keyboard options:
- keyboard = { name, ... }: {
- options = {
- name = lib.mkOption {
- type = lib.types.str;
- example = "laptop-internal";
- description = "Keyboard name.";
- };
-
- device = lib.mkOption {
- type = lib.types.path;
- example = "/dev/input/by-id/some-dev";
- description = "Path to the keyboard's device file.";
- };
-
- extraGroups = lib.mkOption {
- type = lib.types.listOf lib.types.str;
- default = [ ];
- example = [ "openrazer" ];
- description = ''
- Extra permission groups to attach to the KMonad instance for
- this keyboard.
-
- Since KMonad runs as an unprivileged user, it may sometimes
- need extra permissions in order to read the keyboard device
- file. If your keyboard's device file isn't in the input
- group you'll need to list its group in this option.
- '';
- };
-
- defcfg = {
- enable = lib.mkEnableOption ''
- Automatically generate the defcfg block.
-
- When this is option is set to true the config option for
- this keyboard should not include a defcfg block.
- '';
-
- compose = {
- key = lib.mkOption {
- type = lib.types.nullOr lib.types.str;
- default = "ralt";
- description = "The (optional) compose key to use.";
- };
-
- delay = lib.mkOption {
- type = lib.types.int;
- default = 5;
- description = "The delay (in milliseconds) between compose key sequences.";
- };
- };
-
- fallthrough = lib.mkEnableOption "Reemit unhandled key events.";
-
- allowCommands = lib.mkEnableOption "Allow keys to run shell commands.";
- };
-
- config = lib.mkOption {
- type = lib.types.lines;
- description = "Keyboard configuration.";
- };
- };
-
- config = {
- name = lib.mkDefault name;
- };
- };
-
- # Create a complete KMonad configuration file:
- mkCfg = keyboard:
- let defcfg = ''
- (defcfg
- input (device-file "${keyboard.device}")
- output (uinput-sink "kmonad-${keyboard.name}")
- '' +
- lib.optionalString (keyboard.defcfg.compose.key != null) ''
- cmp-seq ${keyboard.defcfg.compose.key}
- cmp-seq-delay ${toString keyboard.defcfg.compose.delay}
- '' + ''
- fallthrough ${lib.boolToString keyboard.defcfg.fallthrough}
- allow-cmd ${lib.boolToString keyboard.defcfg.allowCommands}
- )
- '';
- in
- pkgs.writeTextFile {
- name = "kmonad-${keyboard.name}.cfg";
- text = lib.optionalString keyboard.defcfg.enable (defcfg + "\n") + keyboard.config;
- checkPhase = "${cfg.package}/bin/kmonad -d $out";
- };
-
- # Build a systemd path config that starts the service below when a
- # keyboard device appears:
- mkPath = keyboard: rec {
- name = "kmonad-${keyboard.name}";
- value = {
- description = "KMonad trigger for ${keyboard.device}";
- wantedBy = [ "default.target" ];
- pathConfig.Unit = "${name}.service";
- pathConfig.PathExists = keyboard.device;
- };
- };
-
- # Build a systemd service that starts KMonad:
- mkService = keyboard:
- let
- cmd = [
- "${cfg.package}/bin/kmonad"
- # NOTE: Removed because of version mismatch with 0.4.1 also because this is redundant
- # "--input"
- # ''device-file "${keyboard.device}"''
- ] ++ cfg.extraArgs ++ [
- "${mkCfg keyboard}"
- ];
-
- groups = [
- "input"
- "uinput"
- ] ++ keyboard.extraGroups;
- in
- {
- name = "kmonad-${keyboard.name}";
- value = {
- description = "KMonad for ${keyboard.device}";
- script = lib.escapeShellArgs cmd;
- serviceConfig.Restart = "no";
- serviceConfig.User = "kmonad";
- serviceConfig.SupplementaryGroups = groups;
- serviceConfig.Nice = -20;
- };
- };
-in
-{
- options.services.kmonad = {
- enable = lib.mkEnableOption "KMonad: An advanced keyboard manager.";
-
- package = lib.mkOption {
- type = lib.types.package;
- default = pkgs.kmonad;
- example = "pkgs.haskellPackages.kmonad";
- description = "The KMonad package to use.";
- };
-
- keyboards = lib.mkOption {
- type = lib.types.attrsOf (lib.types.submodule keyboard);
- default = { };
- description = "Keyboard configuration.";
- };
-
- extraArgs = lib.mkOption {
- type = lib.types.listOf lib.types.str;
- default = [ ];
- example = [ "--log-level" "debug" ];
- description = "Extra arguments to pass to KMonad.";
- };
- };
-
- config = lib.mkIf cfg.enable {
- environment.systemPackages = [ cfg.package ];
-
- users.groups.uinput = { };
- users.groups.kmonad = { };
-
- users.users.kmonad = {
- description = "KMonad system user.";
- group = "kmonad";
- isSystemUser = true;
- };
-
- services.udev.extraRules = ''
- # KMonad user access to /dev/uinput
- KERNEL=="uinput", MODE="0660", GROUP="uinput", OPTIONS+="static_node=uinput"
- '';
-
- systemd.paths =
- builtins.listToAttrs
- (map mkPath (builtins.attrValues cfg.keyboards));
-
- systemd.services =
- builtins.listToAttrs
- (map mkService (builtins.attrValues cfg.keyboards));
- };
-}
diff --git a/modules/keyboard/kmonad.nix b/modules/keyboard/kmonad.nix
deleted file mode 100644
index 61312b1..0000000
--- a/modules/keyboard/kmonad.nix
+++ /dev/null
@@ -1,32 +0,0 @@
-{ pkgs, ... }:
-let
- kmonadVersion = "0.4.1";
- # kmonadNixRev = "ac3c0db4f7fca0f66980d1b76a64630a66a36c21";
-
- kmonadBin = pkgs.fetchurl {
- url = "https://github.com/kmonad/kmonad/releases/download/${kmonadVersion}/kmonad-${kmonadVersion}-linux";
- sha256 = "sha256-g55Y58wj1t0GhG80PAyb4PknaYGJ5JfaNe9RlnA/eo8=";
- };
-
- kmonadPkg = pkgs.runCommand "kmonad" { }
- ''#!${pkgs.stdenv.shell}
- mkdir -p $out/bin
- cp ${kmonadBin} $out/bin/kmonad
- chmod +x $out/bin/*
- '';
-
- # kmonadGit = builtins.fetchTarball {
- # url = "https://github.com/kmonad/kmonad/archive/${kmonadNixRev}.tar.gz";
- # sha256 = "sha256:0pjb8971f7z27w7py4n0zm8acjpylj7wz7vx8iz3i7qmj6k45c2y";
- # };
-in
-{
- imports = [
- ./kmonad-nixos-module.nix
- # "${kmonadGit}/nix/nixos-module.nix"
- ];
-
- services.kmonad = {
- package = kmonadPkg;
- };
-}