summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarek Fajkus <marek.faj@gmail.com>2019-10-12 21:35:11 +0200
committerMarek Fajkus <marek.faj@gmail.com>2019-12-13 18:19:29 +0100
commit7406c0af9820b0734ad13421a8033fb9458c110b (patch)
tree9b6d7b52d62d7141e14806963e76e8b572f750b1
parent2cbb2590aa0954a07cb4ed1825024e9863dc03c1 (diff)
downloadnixpkgs-7406c0af9820b0734ad13421a8033fb9458c110b.tar
nixpkgs-7406c0af9820b0734ad13421a8033fb9458c110b.tar.gz
nixpkgs-7406c0af9820b0734ad13421a8033fb9458c110b.tar.bz2
nixpkgs-7406c0af9820b0734ad13421a8033fb9458c110b.tar.lz
nixpkgs-7406c0af9820b0734ad13421a8033fb9458c110b.tar.xz
nixpkgs-7406c0af9820b0734ad13421a8033fb9458c110b.tar.zst
nixpkgs-7406c0af9820b0734ad13421a8033fb9458c110b.zip
services.xserver.imwheel: add module
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/x11/imwheel.nix68
-rw-r--r--pkgs/tools/X11/imwheel/default.nix13
3 files changed, 78 insertions, 4 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index bb217d873bb..e577ea9ab05 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -866,6 +866,7 @@
   ./services/x11/hardware/digimend.nix
   ./services/x11/hardware/cmt.nix
   ./services/x11/gdk-pixbuf.nix
+  ./services/x11/imwheel.nix
   ./services/x11/redshift.nix
   ./services/x11/urxvtd.nix
   ./services/x11/window-managers/awesome.nix
diff --git a/nixos/modules/services/x11/imwheel.nix b/nixos/modules/services/x11/imwheel.nix
new file mode 100644
index 00000000000..871f8851a7e
--- /dev/null
+++ b/nixos/modules/services/x11/imwheel.nix
@@ -0,0 +1,68 @@
+{ config, lib, pkgs, ... }:
+with lib;
+let
+  cfg = config.services.xserver.imwheel;
+in
+  {
+    options = {
+      services.xserver.imwheel = {
+        enable = mkEnableOption "IMWheel service";
+
+        extraOptions = mkOption {
+          type = types.listOf types.str;
+          default = [ "--buttons 45" ];
+          example = [ "--debug" ];
+          description = ''
+            Additional command-line arguments to pass to
+            <command>imwheel</command>.
+          '';
+        };
+
+        rules = mkOption {
+          type = types.attrsOf types.str;
+          default = {};
+          example = literalExample ''
+            ".*" = '''
+              None,      Up,   Button4, 8
+              None,      Down, Button5, 8
+              Shift_L,   Up,   Shift_L|Button4, 4
+              Shift_L,   Down, Shift_L|Button5, 4
+              Control_L, Up,   Control_L|Button4
+              Control_L, Down, Control_L|Button5
+            ''';
+          '';
+          description = ''
+            Window class translation rules.
+            /etc/X11/imwheelrc is generated based on this config
+            which means this config is global for all users.
+            See <link xlink:href="http://imwheel.sourceforge.net/imwheel.1.html">offical man pages</link>
+            for more informations.
+          '';
+        };
+      };
+    };
+
+    config = mkIf cfg.enable {
+      environment.systemPackages = [ pkgs.imwheel ];
+
+      environment.etc."X11/imwheel/imwheelrc".source =
+        pkgs.writeText "imwheelrc" (concatStringsSep "\n\n"
+          (mapAttrsToList
+            (rule: conf: "\"${rule}\"\n${conf}") cfg.rules
+          ));
+
+      systemd.user.services.imwheel = {
+        description = "imwheel service";
+        wantedBy = [ "graphical-session.target" ];
+        partOf = [ "graphical-session.target" ];
+        serviceConfig = {
+          ExecStart = "${pkgs.imwheel}/bin/imwheel " + escapeShellArgs ([
+            "--detach"
+            "--kill"
+          ] ++ cfg.extraOptions);
+          ExecStop = "${pkgs.procps}/bin/pkill imwheel";
+          Restart = "on-failure";
+        };
+      };
+    };
+  }
diff --git a/pkgs/tools/X11/imwheel/default.nix b/pkgs/tools/X11/imwheel/default.nix
index f33e15e59cc..efed00f9639 100644
--- a/pkgs/tools/X11/imwheel/default.nix
+++ b/pkgs/tools/X11/imwheel/default.nix
@@ -10,10 +10,15 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ libX11 libXext libXi libXmu libXt libXtst ];
 
-  postPatch = ''
-    substituteInPlace Makefile.in --replace "ETCDIR = " "ETCDIR = $out"
-    substituteInPlace util.c --replace "/etc/X11/imwheel" "$out/etc/X11/imwheel"
-  '';
+  makeFlags = [
+    "sysconfdir=/etc"
+    "ETCDIR=/etc"
+  ];
+
+  installFlags = [
+    "sysconfdir=${placeholder "out"}/etc"
+    "ETCDIR=${placeholder "out"}/etc"
+  ];
 
   meta = with stdenv.lib; {
     homepage = "http://imwheel.sourceforge.net/";