Home-manager's Espanso module does not create config directory

I am trying to play with Espanso and I have two problems:

  1. home-manager does not install the espanso package, I have to also include the espanso-wayland package under the home.packages = with pkgs; [ list in my home.nix file.
  2. it does create the ~/.config/espanso directory with the ~/.config/espanso/matches subdirectory, but it does not create the ~/.config/espanso/config directory, so espanso gives an error instead of starting. It works if I manually create the config directory.

This is my services.espanso snippet:

  services.espanso = {
    enable = true;
    configs = {
      default = {
      };
    };
    package = pkgs.espanso-wayland;
    wayland = true;
    matches = {
      matches = [
        {
          trigger = ":hello";
          replace = ''world'';
        }
      ];
      base = {
        matches = [
          {
            trigger = ":now";
            replace = "It's {{currentdate}} {{currenttime}}";
          }
        ];
      };
    };
  };

Neither setting package = pkgs.espanso-wayland; nor wayland = true; installed the package. I added the configs line in a vain attempt to create it based on the default example given in the espanso entry of man home-configuration.nix

Nobody else seems to be having these problems when I search. What am I doing wrong?

What’s the error printed by espanso?

Sorry for the late response.

If I run espanso daemon from the terminal, it produces this output:

18:33:28 [daemon(188114)] [INFO] reading configs from: "/home/user/.config/espanso"
18:33:28 [daemon(188114)] [INFO] reading packages from: "/home/user/.config/espanso/match/packages"
18:33:28 [daemon(188114)] [INFO] using runtime dir: "/home/user/.cache/espanso"
18:33:28 [daemon(188114)] [INFO] system info: NixOS v24.11 - kernel: 6.6.52
18:33:28 [daemon(188114)] [WARN] keyboard layout watcher couldn't determine active layout.
18:33:28 [daemon(188114)] [INFO] watching for changes in path: "/home/user/.config/espanso"

(.espanso-wrapped:188119): Gdk-WARNING **: 18:33:30.355: ../gdk/wayland/gdkcursor-wayland.c:243 cursor image size (9x16) not an integermultiple of scale (2)

then creates a pop-up window where it says

[ERROR] unable to load config

Caused by:
    missing config directory

So, it appears not to be generating the configs as it should.

Those paths are obviously missing the username. Do you have any idea why that would be?

user is the username, the path is /home/user/.config/espanso

It happens when I use it with a more inspired username as well lol

Does /home/user/.config/espanso exist?

I explicitly set some config:

{ pkgs, config,  ... }:

{
  services.espanso = {
    enable = true;
    package = pkgs.espanso-wayland;
    configs = {
      default = {
         toggle_key = "ALT";
         keyboard_layout = {
            layout = "us";
         };
      };
    };
    matches = {
      base = {
        matches = [
          {
            trigger = ":now";
            replace = "It's {{currentdate}} {{currenttime}}";
          }
          {
            trigger = ":hello";
            replace = "line1\nline2";
          }
          {
            regex = ":hi(?P.*)\\.";
            replace = "Hi {{person}}!";
          }
        ];
      };
      global_vars = {
        global_vars = [
          {
            name = "currentdate";
            type = "date";
            params = {format = "%d/%m/%Y";};
          }
          {
            name = "currenttime";
            type = "date";
            params = {format = "%R";};
          }
        ];
      };
    };
  };
}

does that help? I have some trouble between HM generations and will need to unregister the service and register the service. Not enough motivation to track that down until now.

Yes, it contains only ~/.config/espanso/configs/default.yml

But upon further inspection, that appears to be the result only of this:

  xdg.configFile = {
    "./espanso/configs/default.yml" = {
      enable = true;
      target = "./espanso/configs/default.yml";
      text =
        ''
          '';
      executable = false;
      onChange = ""; # shell command to run when file has changed between generations
    };
  };

Which I had added to try to get espanso do anything.

That does create the directory, but espanso still doesn’t start. When I explicitly run espanso start or espanso daemon it throws errors.

journalctl --user -xeu espanso.service results in this:

worker(4283)] [ERROR] Unable to open EVDEV devices, this usually has to do with permissions.
worker(4283)] [ERROR] You can either add the current user to the 'input' group or run espanso as root
worker(4283)] [ERROR] thread 'engine thread' panicked at 'failed to initialize detector module: detection source initialization failed': espanso/src/cli/worker/engine/mod.rs:141
worker(4283)] [ERROR] Unable to block the LinuxEventLoop: receiving on an empty and disconnected channel
worker(4283)] [ERROR] thread 'main' panicked at 'unable to run main eventloop: receiving on an empty and disconnected channel': espanso/src/cli/worker/mod.rs:160
daemon(4277)] [ERROR] received unexpected exit code from worker 101, exiting
thread 'main' panicked at espanso/src/cli/launcher/mod.rs:213:45
launch daemon: unexpected error, 'espanso daemon' returned a non-zero exit code.
with `RUST_BACKTRACE=1` environment variable to display a backtrace
in process exited, code=exited, status=101/n/a

Not sure where to go from here.

I am running unstable. Behavior has changed recently, but I can start it and I can register and unregister the service. Not enough time to get down to the root of the problem yet

I am also running unstable, but I have never been able to get espanso to work.

Implementation:

Something should end up by default in ~/.config/espanso. Does that not exist?

Sorry, that has been asked and answered. So, if you remove that custom config file, does that file not get created?

There seems to be some general problems with espanso. While it was working fine with just the package in unstable, after a recent rebuild I was reminded that I had to use a workaround outlined in

in particular the solution in espanso-wayland: service start failure · Issue #249364 · NixOS/nixpkgs · GitHub

works for me right now…

It looks like that does not work for me. When I tried that solution, it gives me this error:

       error: attribute 'security' missing
       at /nix/store/zchh9iv3l65z9fdf1v6gxn20sbk0bpp8-source/nixos/modules/programs/espanso-capdacoverride/default.nix:46:43:
           45|           espanso-wayland = pkgs.callPackage ./espanso-capdacoverride.nix {
           46|             capDacOverrideWrapperDir = "${config.security.wrapperDir}";
             |                                           ^
           47|             espanso = cfg.package;

It happens even when I don’t have the espanso package, so I am thinking the problem is in the origin flake.