about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJörg Thalheim <Mic92@users.noreply.github.com>2017-09-02 08:24:57 +0100
committerGitHub <noreply@github.com>2017-09-02 08:24:57 +0100
commit7b20952c04cc1881477252525e0b21b15f45a42a (patch)
treebbab93b595bd472f010282c4b9b2b986b749609e
parenta020ca5f3566546fcc8a7aa69869c1dc9a91cf3e (diff)
parente0b44a09b84ed462b98b2c1fa841253be801ef8c (diff)
downloadnixlib-7b20952c04cc1881477252525e0b21b15f45a42a.tar
nixlib-7b20952c04cc1881477252525e0b21b15f45a42a.tar.gz
nixlib-7b20952c04cc1881477252525e0b21b15f45a42a.tar.bz2
nixlib-7b20952c04cc1881477252525e0b21b15f45a42a.tar.lz
nixlib-7b20952c04cc1881477252525e0b21b15f45a42a.tar.xz
nixlib-7b20952c04cc1881477252525e0b21b15f45a42a.tar.zst
nixlib-7b20952c04cc1881477252525e0b21b15f45a42a.zip
Merge pull request #28726 from vyp/interception-tools
interception-tools: init at 0.1.1
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/hardware/interception-tools.nix61
-rw-r--r--pkgs/tools/inputmethods/interception-tools/caps2esc.nix23
-rw-r--r--pkgs/tools/inputmethods/interception-tools/default.nix33
-rw-r--r--pkgs/tools/inputmethods/interception-tools/fix-udevmon-configuration-job-path.patch32
-rw-r--r--pkgs/top-level/all-packages.nix22
6 files changed, 172 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index adb21f7b7d95..641a9e6095e5 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -226,6 +226,7 @@
   ./services/hardware/brltty.nix
   ./services/hardware/freefall.nix
   ./services/hardware/illum.nix
+  ./services/hardware/interception-tools.nix
   ./services/hardware/irqbalance.nix
   ./services/hardware/nvidia-optimus.nix
   ./services/hardware/pcscd.nix
diff --git a/nixos/modules/services/hardware/interception-tools.nix b/nixos/modules/services/hardware/interception-tools.nix
new file mode 100644
index 000000000000..fadcb19a016f
--- /dev/null
+++ b/nixos/modules/services/hardware/interception-tools.nix
@@ -0,0 +1,61 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.services.interception-tools;
+in {
+  options.services.interception-tools = {
+    enable = mkOption {
+      type = types.bool;
+      default = false;
+      description = "Whether to enable the interception tools service.";
+    };
+
+    plugins = mkOption {
+      type = types.listOf types.package;
+      default = [ pkgs.interception-tools-plugins.caps2esc ];
+      description = ''
+        A list of interception tools plugins that will be made available to use
+        inside the udevmon configuration.
+      '';
+    };
+
+    udevmonConfig = mkOption {
+      type = types.either types.str types.path;
+      default = ''
+        - JOB: "intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE"
+          DEVICE:
+            EVENTS:
+              EV_KEY: [KEY_CAPSLOCK, KEY_ESC]
+      '';
+      example = ''
+        - JOB: "intercept -g $DEVNODE | y2z | x2y | uinput -d $DEVNODE"
+          DEVICE:
+            EVENTS:
+              EV_KEY: [KEY_X, KEY_Y]
+      '';
+      description = ''
+        String of udevmon YAML configuration, or path to a udevmon YAML
+        configuration file.
+      '';
+    };
+  };
+
+  config = mkIf cfg.enable {
+    systemd.services.interception-tools = {
+      description = "Interception tools";
+      path = [ pkgs.bash pkgs.interception-tools ] ++ cfg.plugins;
+      serviceConfig = {
+        ExecStart = ''
+          ${pkgs.interception-tools}/bin/udevmon -c \
+          ${if builtins.typeOf cfg.udevmonConfig == "path"
+          then cfg.udevmonConfig
+          else pkgs.writeText "udevmon.yaml" cfg.udevmonConfig}
+        '';
+        Nice = -20;
+      };
+      wantedBy = [ "multi-user.target" ];
+    };
+  };
+}
diff --git a/pkgs/tools/inputmethods/interception-tools/caps2esc.nix b/pkgs/tools/inputmethods/interception-tools/caps2esc.nix
new file mode 100644
index 000000000000..b31a24b0c837
--- /dev/null
+++ b/pkgs/tools/inputmethods/interception-tools/caps2esc.nix
@@ -0,0 +1,23 @@
+{ stdenv, fetchurl, cmake }:
+
+let
+  version = "0.1.0";
+  pname = "interception-tools-caps2esc";
+in stdenv.mkDerivation {
+  name = "${pname}-${version}";
+
+  src = fetchurl {
+    url = "https://gitlab.com/interception/linux/plugins/caps2esc/repository/v${version}/archive.tar.gz";
+    sha256 = "1fdxqp54gwsrm2c63168l256nfwdk4mvgr7nlwdv62wd3l7zzrg8";
+  };
+
+  buildInputs = [ cmake ];
+
+  meta = {
+    homepage = "https://gitlab.com/interception/linux/plugins/caps2esc";
+    description = "Transforming the most useless key ever into the most useful one";
+    license = stdenv.lib.licenses.mit;
+    maintainers = stdenv.lib.maintainers.vyp;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/pkgs/tools/inputmethods/interception-tools/default.nix b/pkgs/tools/inputmethods/interception-tools/default.nix
new file mode 100644
index 000000000000..ba54d4954c58
--- /dev/null
+++ b/pkgs/tools/inputmethods/interception-tools/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchurl, fetchFromGitHub, pkgconfig, cmake, libyamlcppWithoutBoost,
+  libevdev, libudev }:
+
+let
+  version = "0.1.1";
+  baseName = "interception-tools";
+in stdenv.mkDerivation {
+  name = "${baseName}-${version}";
+
+  src = fetchurl {
+    url = "https://gitlab.com/interception/linux/tools/repository/v${version}/archive.tar.gz";
+    sha256 = "14g4pphvylqdb922va322z1pbp12ap753hcf7zf9sii1ikvif83j";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ cmake libevdev libudev libyamlcppWithoutBoost ];
+
+  prePatch = ''
+    substituteInPlace CMakeLists.txt --replace \
+      '"/usr/include/libevdev-1.0"' \
+      "\"$(pkg-config --cflags libevdev | cut -c 3-)\""
+  '';
+
+  patches = [ ./fix-udevmon-configuration-job-path.patch ];
+
+  meta = {
+    description = "A minimal composable infrastructure on top of libudev and libevdev";
+    homepage = "https://gitlab.com/interception/linux/tools";
+    license = stdenv.lib.licenses.gpl3;
+    maintainers = stdenv.lib.maintainers.vyp;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/pkgs/tools/inputmethods/interception-tools/fix-udevmon-configuration-job-path.patch b/pkgs/tools/inputmethods/interception-tools/fix-udevmon-configuration-job-path.patch
new file mode 100644
index 000000000000..469c96647d69
--- /dev/null
+++ b/pkgs/tools/inputmethods/interception-tools/fix-udevmon-configuration-job-path.patch
@@ -0,0 +1,32 @@
+From d3a5d661b80f3597368f517ebaeddfdfaafc1bf2 Mon Sep 17 00:00:00 2001
+From: xd1le <elisp.vim@gmail.com>
+Date: Mon, 28 Aug 2017 00:19:09 +1000
+Subject: [PATCH] fix udevmon configuration job path
+
+For some reason, the udevmon job $PATH seems to be empty (or otherwise
+seems to point to `/no-such-path`). This commit fixes that by setting
+its $PATH to the same $PATH that the parent udevmon process has.
+---
+ udevmon.cpp | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/udevmon.cpp b/udevmon.cpp
+index ebdd909..b523efd 100644
+--- a/udevmon.cpp
++++ b/udevmon.cpp
+@@ -237,8 +237,11 @@ private:
+             case 0: {
+                 char *command[] = {(char *)"sh", (char *)"-c",
+                                    (char *)job.c_str(), nullptr};
++                std::string path = getenv("PATH");
+                 std::string variables = "DEVNODE=" + devnode;
+-                char *environment[]   = {(char *)variables.c_str(), nullptr};
++                std::string pathenv = "PATH=" + path;
++                char *environment[] = {(char *)variables.c_str(),
++                                       (char *)pathenv.c_str(), nullptr};
+                 execvpe(command[0], command, environment);
+                 std::fprintf(stderr,
+                              R"(exec failed for devnode %s, job "%s" )"
+-- 
+2.14.1
+
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index e1fe0fa154f4..417c45b73d95 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -1468,6 +1468,11 @@ with pkgs;
     plugins = [ ];
   };
 
+  interception-tools = callPackage ../tools/inputmethods/interception-tools { };
+  interception-tools-plugins = {
+    caps2esc = callPackage ../tools/inputmethods/interception-tools/caps2esc.nix { };
+  };
+
   brotli = callPackage ../tools/compression/brotli { };
 
   brotliUnstable = callPackage ../tools/compression/brotli/unstable.nix { };
@@ -9460,6 +9465,23 @@ with pkgs;
 
   libyamlcpp = callPackage ../development/libraries/libyaml-cpp { };
 
+  # interception-tools needs this. This should be removed when there is a new
+  # release of libyamlcpp, i.e. when the version of libyamlcpp is newer than
+  # 0.5.3.
+  libyamlcppWithoutBoost = libyamlcpp.overrideAttrs (oldAttrs: rec {
+    name = "libyaml-cpp-${version}";
+    version = "2017-08-25";
+
+    src = fetchFromGitHub {
+      owner = "jbeder";
+      repo = "yaml-cpp";
+      rev = "beb44b872c07c74556314e730c6f20a00b32e8e5";
+      sha256 = "1qkr3i5lin6m36w5rbimc7pjx3nx686xnjb6lw00xf67iqrl4h4m";
+    };
+
+    buildInputs = [ cmake ];
+  });
+
   libykneomgr = callPackage ../development/libraries/libykneomgr { };
 
   libytnef = callPackage ../development/libraries/libytnef { };