From 459d83c13b4f903cc425a4c626fd66b1f27317aa Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 16 Nov 2024 17:46:54 +0530 Subject: Switch to upstream kmonad module --- configuration.nix | 2 +- modules/keyboard/default.nix | 3 +- modules/keyboard/kmonad-nixos-module.nix | 187 ------------------------------- modules/keyboard/kmonad.nix | 32 ------ 4 files changed, 3 insertions(+), 221 deletions(-) delete mode 100644 modules/keyboard/kmonad-nixos-module.nix delete mode 100644 modules/keyboard/kmonad.nix diff --git a/configuration.nix b/configuration.nix index 0091723..7024224 100644 --- a/configuration.nix +++ b/configuration.nix @@ -62,7 +62,7 @@ in hostName = "smartfridge"; firewall = { enable = true; - allowedTCPPorts = [ 8080 8081 3000 3001 ]; + allowedTCPPorts = [ 3000 3001 ]; allowedUDPPorts = [ 41641 ]; }; nameservers = [ "100.100.100.100" "8.8.8.8" "1.1.1.1" ]; 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; - }; -} -- cgit v1.3.1