espanso: add crossplatform support

Co-authored-by: Austin Horstman <khaneliman12@gmail.com>
Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
This commit is contained in:
phanirithvij
2024-10-04 22:18:31 +05:30
committed by Austin Horstman
parent 1d2f0b3d4b
commit 29fce40e13
2 changed files with 60 additions and 2 deletions

View File

@@ -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.
'';
}

View File

@@ -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;
};