Fusuma not working?

Hi everyone,

I am unable to make fusuma work on a Thinkpad T480s. My configuration.nix:

environment.systemPackages = with pkgs; [
...
fusuma
xdotool
...
];

My home.nix:

home-manager.users.davide = {
...
  services.fusuma = {
    enable = true;
    extraPackages = with pkgs; [ xdotool ];
    settings = {
      threshold = { swipe = 0.1; };
      interval = { swipe = 0.7; };
      swipe = {
        "3" = {
          left = {
            # GNOME: Switch to left workspace
            command = "xdotool key ctrl+alt+Left";
          };
          right = {
            # GNOME: Switch to right workspace
            command = "xdotool key ctrl+alt+Right";
          };
        };
      };
    };
  };
};

After logging out & logging in, calling fusuma on the terminal returns:

$ fusuma
I, [2022-09-02T22:02:53.614085 #28741]  INFO -- : reload config : /nix/store/pfjcvkbyv7zcdlq22k1h9pm09d1a0qd1-ruby2.7.6-fusuma-1.3.0/lib/ruby/gems/2.7.0/gems/fusuma-1.3.0/lib/fusuma/config.yml
I, [2022-09-02T22:02:53.614131 #28741]  INFO -- : ---------------------------------------------
I, [2022-09-02T22:02:53.614142 #28741]  INFO -- : Fusuma: 1.3.0
I, [2022-09-02T22:02:53.615872 #28741]  INFO -- : libinput: 1.20.1
I, [2022-09-02T22:02:53.617044 #28741]  INFO -- : OS: Linux 5.15.63 #1-NixOS SMP Thu Aug 25 09:40:49 UTC 2022
I, [2022-09-02T22:02:53.618190 #28741]  INFO -- : Distribution: 
<<< Welcome to NixOS 22.05.2807.067d5d5b891 (\m) - \l >>>

Run 'nixos-help' for the NixOS manual.
I, [2022-09-02T22:02:53.620668 #28741]  INFO -- : Desktop session: gnome-xorg
I, [2022-09-02T22:02:53.620696 #28741]  INFO -- : ---------------------------------------------
I, [2022-09-02T22:02:53.620706 #28741]  INFO -- : ---------------------------------------------
I, [2022-09-02T22:02:53.620713 #28741]  INFO -- : Enabled Plugins: 
I, [2022-09-02T22:02:53.620760 #28741]  INFO -- :   Fusuma::Plugin::Buffers::GestureBuffer
I, [2022-09-02T22:02:53.620771 #28741]  INFO -- :   Fusuma::Plugin::Detectors::PinchDetector
I, [2022-09-02T22:02:53.620779 #28741]  INFO -- :   Fusuma::Plugin::Detectors::RotateDetector
I, [2022-09-02T22:02:53.620788 #28741]  INFO -- :   Fusuma::Plugin::Detectors::SwipeDetector
I, [2022-09-02T22:02:53.620794 #28741]  INFO -- :   Fusuma::Plugin::Events::Records::GestureRecord
I, [2022-09-02T22:02:53.620801 #28741]  INFO -- :   Fusuma::Plugin::Events::Records::IndexRecord
I, [2022-09-02T22:02:53.620814 #28741]  INFO -- :   Fusuma::Plugin::Events::Records::TextRecord
I, [2022-09-02T22:02:53.620830 #28741]  INFO -- :   Fusuma::Plugin::Executors::CommandExecutor
I, [2022-09-02T22:02:53.620843 #28741]  INFO -- :   Fusuma::Plugin::Filters::LibinputDeviceFilter
I, [2022-09-02T22:02:53.620855 #28741]  INFO -- :   Fusuma::Plugin::Inputs::LibinputCommandInput
I, [2022-09-02T22:02:53.620870 #28741]  INFO -- :   Fusuma::Plugin::Parsers::LibinputGestureParser
I, [2022-09-02T22:02:53.620884 #28741]  INFO -- : ---------------------------------------------

Thans :slight_smile:
Davide

Looks to me like it’s working, actually. home-manager will create a user service file for you, and automatically start it when you log in.

You can see if it’s running with systemctl status --user fusuma.service, and see its logs with journalctl --user -xe --unit fusuma.service.

My guess is that either the user service is failing because of some configuration mishap you’ll be able to see in the logs, or the second instance in your terminal overrides the user unit one. The user unit will pass the config file location as a CLI arg, so the manually started one doesn’t use the home-manager config.

Thank you for your reply. Indeed the service fails. Both the commands you suggest output the following lines:

status --user fusuma.service     
○ fusuma.service - Fusuma services
     Loaded: loaded (/home/davide/.config/systemd/user/fusuma.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Sat 2022-09-03 17:44:53 BST; 14s ago
    Process: 6137 ExecStart=/nix/store/fdpp2smdg0zh6zh8fks6cq9sqigydv23-fusuma-1.3.0/bin/fusuma -c /home/davide/.config/fusuma/config.yaml (code=exited, status=1/FAILURE)
   Main PID: 6137 (code=exited, status=1/FAILURE)
        CPU: 188ms

Sep 03 17:44:53 nixos fusuma[6137]: I, [2022-09-03T17:44:53.829424 #6137]  INFO -- : libinput: 1.20.1
Sep 03 17:44:53 nixos fusuma[6137]: /nix/store/pfjcvkbyv7zcdlq22k1h9pm09d1a0qd1-ruby2.7.6-fusuma-1.3.0/lib/ruby/gems/2.7.0/gems/fusuma-1.3.0/lib/fusuma.rb:50:in ``': No such file or directory - uname (Errno::ENOENT)
Sep 03 17:44:53 nixos fusuma[6137]:         from /nix/store/pfjcvkbyv7zcdlq22k1h9pm09d1a0qd1-ruby2.7.6-fusuma-1.3.0/lib/ruby/gems/2.7.0/gems/fusuma-1.3.0/lib/fusuma.rb:50:in `print_version'
Sep 03 17:44:53 nixos fusuma[6137]:         from /nix/store/pfjcvkbyv7zcdlq22k1h9pm09d1a0qd1-ruby2.7.6-fusuma-1.3.0/lib/ruby/gems/2.7.0/gems/fusuma-1.3.0/lib/fusuma.rb:36:in `read_options'
Sep 03 17:44:53 nixos fusuma[6137]:         from /nix/store/pfjcvkbyv7zcdlq22k1h9pm09d1a0qd1-ruby2.7.6-fusuma-1.3.0/lib/ruby/gems/2.7.0/gems/fusuma-1.3.0/lib/fusuma.rb:16:in `run'
Sep 03 17:44:53 nixos fusuma[6137]:         from /nix/store/kdcwy5y2sv52z8nv6fki76b2liic47cv-fusuma-1.3.0/lib/ruby/gems/2.7.0/gems/fusuma-1.3.0/exe/fusuma:41:in `<top (required)>'
Sep 03 17:44:53 nixos fusuma[6137]:         from /nix/store/kdcwy5y2sv52z8nv6fki76b2liic47cv-fusuma-1.3.0/bin/.fusuma-wrapped:21:in `load'
Sep 03 17:44:53 nixos fusuma[6137]:         from /nix/store/kdcwy5y2sv52z8nv6fki76b2liic47cv-fusuma-1.3.0/bin/.fusuma-wrapped:21:in `<main>'
Sep 03 17:44:53 nixos systemd[6090]: fusuma.service: Main process exited, code=exited, status=1/FAILURE
Sep 03 17:44:53 nixos systemd[6090]: fusuma.service: Failed with result 'exit-code'.

I read about a problem with a ruby file and recalled that I had not installed ruby. Therefore I commented all the lines referring fo fusuma, added ruby and libinput to my configuration.nix, run sudo nixos-rebuild switch, uncommented the fusuma lines, re-run sudo nixos-rebuild switch and relogged. However, I still get the same message.

Davide

Is it possible that fusuma does not work do to a possible hardware problem in the keyboard?

My laptop’s keyboard probably already has a problem (backlight not working). And I installed the same configuration to a Lenovo T450s (with some differences just in the boot options), and it works ok there.

I’m getting the exact same error, on an XPS 13 fwiw. It only appears when i provide an extraPackages option, but string interpolating the binary i’m trying to call directly doesn’t seem to be calling the command.

UPDATE: I was able to fix this error by adding pkgs.coreutils-full to service.fusuma.extraPackages. My command still isn’t working but it may be helpful to you @dav.dap. Seems like something that could be improved in the fusuma module.

SECOND UPDATE: For any lost voyagers out there, my issue was caused by skimming past the fusuma installation instructions and missing that my user needed to be in the input group :slight_smile:

I’ve been trying to get my head around getting the fusuma plugins in to my NixOS configuration.nix, but to no avail.

I don’t know enough about either Ruby packaging requirements or NixOS (still).

Has anyone got this working?

So the following default.nix, plus the shell.nix below that and running bundler install; bundix to generate the gem files, gets me a working fusuma-sendkey app, but how do I get fusuma to see the plugin?

default.nix:

{ stdenv, lib, bundlerEnv, bundlerUpdateScript, makeWrapper, libinput }:

let gems =
  bundlerEnv {
    name = "fusuma-plugin-sendkey";
    gemdir = ./.;
    copy_gemFile = true;
  };
in stdenv.mkDerivation {
  name = "fusuma-plugin-sendkey";
  exes = [ "fusuma-sendkey" ];
  src = ./.;

  passthru.updateScript = bundlerUpdateScript "fusuma-plugin-sendkey";

  nativeBuildInputs = [ makeWrapper ];
  buildInputs = [ gems ];

  installPhase = ''
    mkdir -p $out/bin
    cp -a $src/lib $out
    makeWrapper $src/exe/fusuma-sendkey $out/bin/fusuma-sendkey
    wrapProgram $out/bin/fusuma-sendkey --prefix PATH : ${lib.makeBinPath [ libinput ]}
  '';

  meta = with lib; {
    description = "Fusuma plugin to send keyboard events";
    homepage = "https://github.com/iberianpig/fusuma-plugin-sendkey";
    license = licenses.mit;
    maintainers = with maintainers; [ ebardie ];
    platforms = platforms.linux;
  };
}

shell.nix:

with import <nixpkgs> {};
stdenv.mkDerivation {
  name = "env";
  buildInputs = [
    ruby.devEnv
    bundix
  ];
}

The ${SOME_SHA}-fusuma-1.3.0 directory in /nix/store doesn’t contain the built-in plugins, they come from a ${ANOTHER_SHA}-ruby2.7.7-fusuma-1.3.0 which the fusuma derivation also creates, though that seems to happen magically, presumably thanks to bundlerApp.

Is it going to be necessary to override the fusuma derivation to somehow pull in the relevant directories from fusuma-plugin-sendkey et al.?

If so, hints on that would be helpful… :slight_smile:

Hmmn, is this made harder by the plugin derivations not being available from pkgs yet 'cos they’re not upstream? Anyhow, how to get them injected in to the right location in the magic ${ANOTHER_SHA}-ruby2.7.7-fusuma-1.3.0

[edit: added the following]

Ah, so fusuma needs the gemspec files too to ensure version compatibility.

fusuma/lib/fusuma/plugin/manager.rb:

   30       def fusuma_external_plugin_paths
   31         @_fusuma_external_plugin_paths ||=
   32           Gem.find_latest_files(search_key).map do |siblings_plugin|
   33             next unless %r{fusuma-plugin-(.+).*/lib/#{plugin_dir_name}/.+\.rb}.match?(siblings_plugin)
   34
   35             match_data = siblings_plugin.match(%r{(.*)/(.*)/lib/(.*)})
   36             gemspec_path = Dir.glob("#{match_data[1]}/#{match_data[2]}/*.gemspec").first
   37             raise "Not Found: #{match_data[1]}/#{match_data[2]}/*.gemspec" unless gemspec_path
   38
   39             gemspec = Gem::Specification.load(gemspec_path)
   40             fusuma_gemspec_path = File.expand_path("../../../fusuma.gemspec", __dir__)
   41             fusuma_gemspec = Gem::Specification.load(fusuma_gemspec_path)
   42
   43             if gemspec.dependencies.find { |d| d.name == "fusuma" }&.match?(fusuma_gemspec)
   44               siblings_plugin
   45             else
   46               MultiLogger.warn "#{gemspec.name} #{gemspec.version} is incompatible with running #{fusuma_gemspec.name} #{fusuma_gemspec.version}"
   47               MultiLogger.warn "gemspec: #{gemspec_path}"
   48               next
   49             end
   50           end.compact.grep_v(exclude_path_pattern).sort
   51       end

I seem to be having a different problem. journalctl log:

Jan 05 05:34:57 udon fusuma[1723925]: /nix/store/fqkm6wvfwqc61zrdhj70idxh433k7s9f-bundler-2.4.22/lib/ruby/gems/3.1.0/gems/bundler-2.4.22/lib/bundler/definition.rb:418:in `ensure_equivalent_gemfile_and_lockfile': Your lock file has an invalid dependency "fusuma-plugin-keypress", but the lockfile can't be updated because frozen mode is set (Bundler::ProductionError)
Jan 05 05:34:57 udon fusuma[1723925]: Run `bundle install` elsewhere and add the updated ../../nix/store/cxvnqijdzqzvcgzfr3yfbd747rayyyax-gemfile-and-lockfile/Gemfile to version control.
Jan 05 05:34:57 udon fusuma[1723925]:         from /nix/store/fqkm6wvfwqc61zrdhj70idxh433k7s9f-bundler-2.4.22/lib/ruby/gems/3.1.0/gems/bundler-2.4.22/lib/bundler/runtime.rb:13:in `setup'
Jan 05 05:34:57 udon fusuma[1723925]:         from /nix/store/fqkm6wvfwqc61zrdhj70idxh433k7s9f-bundler-2.4.22/lib/ruby/gems/3.1.0/gems/bundler-2.4.22/lib/bundler.rb:162:in `setup'
Jan 05 05:34:57 udon fusuma[1723925]:         from /nix/store/8wyp0bx69hg2cck4fq38bm2yjrkakqpl-fusuma-3.1.0/bin/.fusuma-wrapped:33:in `<main>'
Jan 05 05:34:57 udon systemd[1938]: fusuma.service: Main process exited, code=exited, status=1/FAILURE

Edit: terminal was being weird with journalctl output

Edit 2: So it’s actually working when I do nix shell nixpkgs#fusuma and just run fusuma, but not when I set it up in HM.