1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2025-01-09 18:49:51 +01:00

espanso: add crossplatform support

Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
This commit is contained in:
phanirithvij 2024-10-04 22:18:31 +05:30
parent 1e27f213d7
commit 1b9dbef874

View file

@ -4,9 +4,22 @@ let
mkOption mkEnableOption mkIf maintainers literalExpression types mkOption mkEnableOption mkIf maintainers literalExpression types
mkRemovedOptionModule versionAtLeast; mkRemovedOptionModule versionAtLeast;
inherit (pkgs.stdenv.hostPlatform) isDarwin isLinux;
cfg = config.services.espanso; cfg = config.services.espanso;
espansoVersion = cfg.package.version; espansoVersion = cfg.package.version;
package-bin = if isLinux then
pkgs.writeShellScriptBin "espanso" ''
if [ -n "$WAYLAND_DISPLAY" ]; then
${lib.meta.getExe cfg.package-wayland} "$@"
else
${lib.meta.getExe cfg.package} "$@"
fi
''
else
cfg.package;
yaml = pkgs.formats.yaml { }; yaml = pkgs.formats.yaml { };
in { in {
imports = [ imports = [
@ -26,10 +39,38 @@ in {
package = mkOption { package = mkOption {
type = types.package; type = types.package;
description = "Which espanso package to use"; description = "Which espanso package to use";
default = pkgs.espanso; default = if isDarwin || cfg.x11Support then
pkgs.espanso
else
pkgs.espanso-wayland;
defaultText = literalExpression "pkgs.espanso"; defaultText = literalExpression "pkgs.espanso";
}; };
package-wayland = mkOption {
type = types.package;
description =
"Which espanso package to use when running under wayland on linux";
default = if isLinux && 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 on linux";
default = isLinux;
defaultText = literalExpression "enabled on linux";
};
waylandSupport = mkOption {
type = types.bool;
description = "Whether to enable wayland support on linux";
default = isLinux;
defaultText = literalExpression "enabled on linux";
};
configs = mkOption { configs = mkOption {
type = yaml.type; type = yaml.type;
default = { default = { }; }; default = { default = { }; };
@ -98,14 +139,23 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [{ assertions = [
{
assertion = versionAtLeast espansoVersion "2"; assertion = versionAtLeast espansoVersion "2";
message = '' message = ''
The services.espanso module only supports Espanso version 2 or later. The services.espanso module only supports Espanso version 2 or later.
''; '';
}]; }
{
assertion = isLinux -> (cfg.x11Support || cfg.waylandSupport);
message = ''
In services.espanso at least 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 xdg.configFile = let
configFiles = lib.mapAttrs' (name: value: { configFiles = lib.mapAttrs' (name: value: {
@ -121,7 +171,7 @@ in {
systemd.user.services.espanso = { systemd.user.services.espanso = {
Unit = { Description = "Espanso: cross platform text expander in Rust"; }; Unit = { Description = "Espanso: cross platform text expander in Rust"; };
Service = { Service = {
ExecStart = "${cfg.package}/bin/espanso launcher"; ExecStart = "${lib.meta.getExe package-bin} launcher";
Restart = "on-failure"; Restart = "on-failure";
RestartSec = 3; RestartSec = 3;
}; };