Skip to content

Commit

Permalink
espanso: try adding wayland support
Browse files Browse the repository at this point in the history
Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
  • Loading branch information
phanirithvij committed Oct 4, 2024
1 parent 509dbf8 commit 82dc0c3
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions modules/services/espanso.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ let
cfg = config.services.espanso;
espansoVersion = cfg.package.version;

package-bin = pkgs.writeShellScriptBin "espanso" ''
if [ -n "$WAYLAND_DISPLAY" ]; then
${lib.meta.getExe cfg.package-wayland} "$@"
else
${lib.meta.getExe cfg.package} "$@"
fi
'';

yaml = pkgs.formats.yaml { };
in {
imports = [
Expand All @@ -26,10 +34,32 @@ in {
package = mkOption {
type = types.package;
description = "Which espanso package to use";
default = pkgs.espanso;
default = if cfg.x11Support then pkgs.espanso else pkgs.espanso-wayland;
defaultText = literalExpression "pkgs.espanso";
};

package-wayland = mkOption {
type = types.package;
description = "Which espanso package to use when running under wayland";
default =
if cfg.waylandSupport then pkgs.espanso-wayland else pkgs.espanso;
defaultText = literalExpression "pkgs.espanso-wayland";
};

x11Support = mkOption {
type = types.bool;
description = "Whether to enable x11 support";
default = true;
defaultText = literalExpression "true";
};

waylandSupport = mkOption {
type = types.bool;
description = "Whether to enable wayland support";
default = true;
defaultText = literalExpression "true";
};

configs = mkOption {
type = yaml.type;
default = { default = { }; };
Expand Down Expand Up @@ -98,14 +128,23 @@ in {
};

config = mkIf cfg.enable {
assertions = [{
assertion = versionAtLeast espansoVersion "2";
message = ''
The services.espanso module only supports Espanso version 2 or later.
'';
}];
assertions = [
{
assertion = versionAtLeast espansoVersion "2";
message = ''
The services.espanso module only supports Espanso version 2 or later.
'';
}
{
assertion = cfg.x11Support || cfg.waylandSupport;
message = ''
In services.espanso at least x11 or wayland support must be enabled.
'';
}
];

home.packages = [ cfg.package ];
# obviously conflicting to have cfg.package and cfg.package-wayland
home.packages = [ package-bin ];

xdg.configFile = let
configFiles = lib.mapAttrs' (name: value: {
Expand All @@ -122,7 +161,7 @@ in {
Unit = { Description = "Espanso: cross platform text expander in Rust"; };
Service = {
Type = "exec";
ExecStart = "${cfg.package}/bin/espanso daemon";
ExecStart = "${lib.meta.getExe package-bin} daemon";
Restart = "on-failure";
};
Install = { WantedBy = [ "default.target" ]; };
Expand Down

0 comments on commit 82dc0c3

Please sign in to comment.