From 29fce40e1391477b66ef3a24ea7867f0bc5b52a1 Mon Sep 17 00:00:00 2001 From: phanirithvij Date: Fri, 4 Oct 2024 22:18:31 +0530 Subject: [PATCH] espanso: add crossplatform support Co-authored-by: Austin Horstman Signed-off-by: phanirithvij --- modules/misc/news/2025-04-26_18-56-13.nix | 11 +++++ modules/services/espanso.nix | 51 ++++++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 modules/misc/news/2025-04-26_18-56-13.nix diff --git a/modules/misc/news/2025-04-26_18-56-13.nix b/modules/misc/news/2025-04-26_18-56-13.nix new file mode 100644 index 000000000..645deb501 --- /dev/null +++ b/modules/misc/news/2025-04-26_18-56-13.nix @@ -0,0 +1,11 @@ +{ pkgs, config, ... }: +{ + time = "2025-04-26T13:26:13+00:00"; + condition = pkgs.hostPlatform.isLinux && config.services.espanso.enable; + message = '' + `services.espanso` now supports wayland. + This is enabled by default on Linux as `services.espanso.waylandSupport = true;`. + Depending on your graphical session type, you may disable one of `services.espanso.x11Support` and `services.espanso.waylandSupport` to reduce the closure size of espanso on your system. + Both x11 and wayland versions come enabled by default on Linux. + ''; +} diff --git a/modules/services/espanso.nix b/modules/services/espanso.nix index 8bd617da2..b4df0e3be 100644 --- a/modules/services/espanso.nix +++ b/modules/services/espanso.nix @@ -7,6 +7,7 @@ let inherit (lib) mkOption + mkPackageOption mkEnableOption mkIf maintainers @@ -16,9 +17,25 @@ let versionAtLeast ; + inherit (pkgs.stdenv.hostPlatform) isLinux; + cfg = config.services.espanso; espansoVersion = cfg.package.version; + package-bin = + if isLinux && cfg.x11Support && cfg.waylandSupport then + pkgs.writeShellScriptBin "espanso" '' + if [ -n "$WAYLAND_DISPLAY" ]; then + ${lib.meta.getExe cfg.package-wayland} "$@" + else + ${lib.meta.getExe cfg.package} "$@" + fi + '' + else if isLinux && cfg.waylandSupport then + cfg.package-wayland + else + cfg.package; + yaml = pkgs.formats.yaml { }; in { @@ -47,6 +64,29 @@ in defaultText = literalExpression "pkgs.espanso"; }; + package-wayland = + mkPackageOption pkgs "espanso-wayland" { + nullable = true; + extraDescription = "Which `espanso` package to use when running under wayland."; + } + // { + default = if isLinux && cfg.waylandSupport then pkgs.espanso-wayland else null; + }; + + x11Support = mkOption { + type = types.bool; + description = "Whether to enable x11 support on linux"; + default = isLinux; + defaultText = "`true` on linux"; + }; + + waylandSupport = mkOption { + type = types.bool; + description = "Whether to enable wayland support on linux"; + default = isLinux; + defaultText = "`true` on linux"; + }; + configs = mkOption { type = yaml.type; default = { @@ -126,9 +166,16 @@ in The services.espanso module only supports Espanso version 2 or later. ''; } + { + assertion = isLinux -> (cfg.x11Support || cfg.waylandSupport); + message = '' + In services.espanso at least one of x11 or wayland support must be enabled on linux. + ''; + } ]; - home.packages = [ cfg.package ]; + # conflicting to have cfg.package and cfg.package-wayland + home.packages = [ package-bin ]; xdg.configFile = let @@ -152,7 +199,7 @@ in Description = "Espanso: cross platform text expander in Rust"; }; Service = { - ExecStart = "${cfg.package}/bin/espanso launcher"; + ExecStart = "${lib.meta.getExe package-bin} launcher"; Restart = "on-failure"; RestartSec = 3; };