Using Espanso on Wayland NixOS

I posted this topic because espanso was not creating the directories I thought I was telling it to. That problem is solved. Now espanso claims it starts, and systemctl claims espanso is running, but I cannot actually use any of the expansion triggers I have in it, and when I try to do espanso commands directly from the terminal, espanso says it isn’t running. Any help would be much obliged.

~ 
󰂃 87% ➜ :now 
:now: command not found

~ 
󰂃 87% ➜ espanso service unregister && espanso service register
disabling espanso systemd service
Removed '/home/user/.config/systemd/user/default.target.wants/espanso.service'.
deleting espanso systemd entry
service unregistered correctly!
creating service file in "/home/user/.config/systemd/user/espanso.service"
enabling systemd service
Created symlink '/home/user/.config/systemd/user/default.target.wants/espanso.service' → '/home/user/.config/systemd/user/espanso.service'.
service registered correctly!

~ 
󰂃 87% ➜ systemctl --user stop espanso.service

~ 
󰂃 87% ➜ systemctl --user start espanso.service

~ 
󰂃 87% ➜ systemctl --user status espanso.service
● espanso.service - espanso
     Loaded: loaded (/home/user/.config/systemd/user/espanso.service; enabled; preset: ignored)
     Active: activating (auto-restart) (Result: exit-code) since Thu 2024-10-31 09:43:26 CST; 2s ago
 Invocation: d7e8a616c71347e7a132e6c54c1ffedc
    Process: 168007 ExecStart=/nix/store/1kzp0d57fi1z1gr7kfpvz9ixahccai41-espanso-2.2-unstable-2024-05-14/b>
   Main PID: 168007 (code=exited, status=101)
   Mem peak: 15.6M
        CPU: 177ms

~ took 6s 
󰂃 87% ➜ espanso match exec --trigger :now
unable to exec match: Worker process is not running, please start Espanso first.

~
󰂃 86% ➜ espanso daemon
09:45:50 [daemon(169160)] [INFO] reading configs from: "/home/user/.config/espanso"
09:45:50 [daemon(169160)] [INFO] reading packages from: "/home/user/.config/espanso/match/packages"
09:45:50 [daemon(169160)] [INFO] using runtime dir: "/home/user/.cache/espanso"
09:45:50 [daemon(169160)] [INFO] system info: NixOS v24.11 - kernel: 6.6.58
09:45:50 [daemon(169160)] [WARN] keyboard layout watcher couldn't determine active layout.
09:45:50 [daemon(169160)] [INFO] espanso version: 2.2.1
09:45:50 [daemon(169160)] [INFO] spawning the worker process...
09:45:50 [daemon(169160)] [INFO] watching for changes in path: "/home/user/.config/espanso"
09:45:50 [daemon(169160)] [INFO] binded to IPC unix socket: /home/user/.cache/espanso/espansodaemonv2.sock
09:45:50 [worker(169166)] [INFO] reading configs from: "/home/user/.config/espanso"
09:45:50 [worker(169166)] [INFO] reading packages from: "/home/user/.config/espanso/match/packages"
09:45:50 [worker(169166)] [INFO] using runtime dir: "/home/user/.cache/espanso"
09:45:50 [worker(169166)] [INFO] system info: NixOS v24.11 - kernel: 6.6.58
09:45:50 [worker(169166)] [INFO] binded to IPC unix socket: /home/user/.cache/espanso/espansoworkerv2.sock
09:45:50 [worker(169166)] [INFO] using WaylandAppInfoProvider
09:45:50 [worker(169166)] [WARN] EVDEV backend is being used, but without enabling linux capabilities.
09:45:50 [worker(169166)] [INFO] monitoring the status of the daemon process
09:45:50 [worker(169166)] [WARN]   Although you CAN run espanso EVDEV backend as root, it's not recommended due
09:45:50 [worker(169166)] [WARN]   to security reasons. Espanso supports linux capabilities to limit the attack surface
09:45:50 [worker(169166)] [WARN]   area by only leveraging on the CAP_DAC_OVERRIDE capability (needed to work with
09:45:50 [worker(169166)] [WARN]   /dev/input/* devices to detect and inject text) and disabling it as soon as the
09:45:50 [worker(169166)] [WARN]   initial setup is completed.
09:45:50 [worker(169166)] [INFO] detection module will use this keyboard layout: [R=, M=, L=us, V=, O=]
09:45:50 [worker(169166)] [INFO] using EVDEVSource
09:45:50 [worker(169166)] [ERROR] Unable to open EVDEV devices, this usually has to do with permissions.
09:45:50 [worker(169166)] [ERROR] You can either add the current user to the 'input' group or run espanso as root
09:45:50 [worker(169166)] [ERROR] thread 'engine thread' panicked at 'failed to initialize detector module: detection source initialization failed': espanso/src/cli/worker/engine/mod.rs:141
09:45:50 [worker(169166)] [ERROR] Unable to block the LinuxEventLoop: receiving on an empty and disconnected channel
09:45:50 [worker(169166)] [ERROR] thread 'main' panicked at 'unable to run main eventloop: receiving on an empty and disconnected channel': espanso/src/cli/worker/mod.rs:160
09:45:50 [daemon(169160)] [ERROR] received unexpected exit code from worker 101, exiting

~ took 7s 
󰂃 85% ➜ espanso start
unable to start service: timed out
Hint: sometimes this happens because another Espanso process is left running for some reason.
      Please try running 'espanso restart' or manually killing all Espanso processes, then try again.

~ took 7s 
󰂃 85% ➜ espanso restart
espanso is not running!
unable to start service: timed out
Hint: sometimes this happens because another Espanso process is left running for some reason.
      Please try running 'espanso restart' or manually killing all Espanso processes, then try again.

This looks to me like issue #249364. Espanso under Wayland requires extra capabilities if you’re not running it as root. This cannot be easily achieved on NixOS. One way is my PR #328890 that adds a module fixing the problem when activated. While it (or a better solution) is not yet merged, it should be comparatively easy to include in a flake-based configuration, see my comment here.

I had actually tried that and I couldn’t make it work, but this time you suggested it, I tried again and it worked, so it was obviously just user error lol

Thank you

Glad to hear that it works :slight_smile:!

The fix is working for me too. But, after fixing my flake like mentioned, I had to run these commands:

espanso service unregister && espanso service register
espanso start

There are two relevant nixpkgs PRs that have been merged this week. It should not require any workarounds or manual action anymore. The only required config going forward is

{
  services.espanso = {
    enable = true;
    package = pkgs.espanso-wayland;
  };
}

The PRs are:

2 Likes

So I’m currently trying this, with espanso-wayland from unstable and somehow have the exact same capabilities error still.
nixpkgs-unstable: github:nixos/nixpkgs/dc205f7b4fdb04c8b7877b43edb7b73be7730081

[INFO] espanso version: 2.3.0
[WARN] keyboard layout watcher couldn't determine active layout.
[INFO] watching for changes in path: /home/xbagon/.config/espanso
[INFO] spawning the worker process...
[INFO] binded to IPC unix socket: /home/xbagon/.cache/espanso/espansodaemonv2.sock
[INFO] reading configs from: "/home/xbagon/.config/espanso"
[INFO] reading packages from: "/home/xbagon/.config/espanso/match/packages"
[INFO] using runtime dir: "/home/xbagon/.cache/espanso"
[INFO] system info: NixOS v25.05 - kernel: 6.17.8
[INFO] kdotool missing or not available for the current wayland DE.
[INFO] binded to IPC unix socket: /home/xbagon/.cache/espanso/espansoworkerv2.sock
[INFO] kdotool missing or not available for the current wayland DE.
[INFO] monitoring the status of the daemon process
[INFO] no appropriate WaylandAppInfoProvider found for current DE/WM
[WARN] EVDEV backend is being used, but without enabling linux capabilities.
[WARN]   Although you CAN run espanso EVDEV backend as root, it's not recommended due
[WARN]   to security reasons. Espanso supports linux capabilities to limit the attack surface
[WARN]   area by only leveraging on the CAP_DAC_OVERRIDE capability (needed to work with
[WARN]   /dev/input/* devices to detect and inject text) and disabling it as soon as the
[WARN]   initial setup is completed.
[WARN] unable to determine keyboard layout automatically, please explicitly specify it in the configuration.
[INFO] using EVDEVSource
[ERROR] Unable to open EVDEV devices, this usually has to do with permissions.
[ERROR] You can either add the current user to the 'input' group or run espanso as root
[ERROR] thread 'engine thread' panicked at 'failed to initialize detector module: detection source initialization failed': espanso/src/cli/worker/engine/mod.rs:146
[ERROR] Unable to block the LinuxEventLoop: receiving on an empty and disconnected channel
[ERROR] thread 'main' panicked at 'unable to run main eventloop: receiving on an empty and disconnected channel': espanso/src/cli/worker/mod.rs:153
[ERROR] received unexpected exit code from worker 101, exiting

EDIT: I guess the problem is the service is not the updated one from unstable?

EDIT2:

  imports =
    "${nixpkgs-custom}/nixos/modules/services/desktops/espanso.nix"
  ];
  disabledModules = [
    "services/desktops/espanso.nix"
  ];

did indeed fix it for me!
but it required fixing the service module

--- a/nixos/modules/services/desktops/espanso.nix
+++ b/nixos/modules/services/desktops/espanso.nix
@@ -29,9 +29,7 @@ in
       capabilities = "cap_dac_override+p";
       owner = "root";
       group = "root";
-      source = lib.getExe (
-        pkgs.espanso-wayland.override { securityWrapperPath = config.security.wrapperDir; }
-      );
+      source = lib.getExe (cfg.package.override { securityWrapperPath = config.security.wrapperDir; });
     };
     systemd.user.services.espanso = {
       description = "Espanso daemon";

EDIT3:

this also makes the shell extension works, but whenever you want to execute another command from the shell, it can’t find it so I’m currently working around it with /home/username/.nix-profile/bin/command.

You need both the new module and the updated package, make sure you’re overriding the package as well.

1 Like

one thing that doesn’t seem to work is clipboard expansion, very noticeable when trying to use the emoji package or just setting backend: Clipboard

1 Like

Still not working. The fix is still needed. I tried 25.05 and unstable.

Espanso is not always working after the computer has slept.

I have to stop it and restart it to make it work again:

espanso stop
espanso start

Working fine for me. x86_64-linux, sway, following unstable.

In my configuration, I have now:

services.espanso = {
enable = true;
package = unstable.espanso-wayland;
};

unstable provides me with access to unstable packages.

It is not working. Do I need something else?

That should be all you need, assuming your unstable is not pointing to a commit from a month ago.

What DE / WM are you using?

Is your config public?

I am using Gnome.

Yes. My config.

That would be nice to take a look. I don’t understand what’s going on.

Note that at the time I’m writing, this config is working with the fix of pitkling.

If I remove the fix and use unstable like the previous example, it does not work.

Unrelated suggested change:

- unstable = import nixpkgs-unstable { system = "x86_64-linux"; };
+ unstable = nixpkgs-unstable.legacyPackages.x86_64-linux; };

Still looking into it.

I wonder if using pkgs.espanso-wayland instead of cfg.package may be an issue? Perhaps it’s using your pkgs instead of unstable?

Wondering because systemctl --user cat espanso is showing an older 2.2.x version when I build your config into a vm, even when I specify the package to use unstable.

I would think an overlay would fix it if so, but my initial test doesn’t seem to take effect.

@Pierre-Thibault

Yes, it looks like my comment above is likely the issue – can you try nixos/espanso: reference the current configuration's package by n8henrie · Pull Request #467180 · NixOS/nixpkgs · GitHub and make sure it fixes things for you? (You’ll need to use the module as well as specify the espanso package from this PR.)

FWIW I’m using an Asahi system on ZFS that is pinned to the latest commit for which ZFS kernel builds (~Aug 2025); as this system is older than the PR we merged for wayland support, I get the same error when I try to use the package + module from the PR on this slightly older system.

@niklaskorz if you’re available for a review would greatly appreciate it! If acceptable to be merged should likely also be backported :man_facepalming:

@n8henrie I have upgraded from NixOS 25.05 to 25.11. I can no longer apply the Espanso fix. Otherwise, I have an error and Espanso is no longer working.

What should I do?

That fix is already backported to nixos-25.11.

2 Likes