From 59d50bc582bdf439df096a9ae1781e6c9c8a7523 Mon Sep 17 00:00:00 2001 From: Nathan Henrie Date: Mon, 15 Apr 2024 01:40:27 -0600 Subject: [PATCH] espanso: enable module on darwin --- modules/services/espanso.nix | 34 ++++++++---- tests/default.nix | 1 + .../espanso-darwin/basic-configuration.nix | 55 +++++++++++++++++++ .../services/espanso-darwin/default.nix | 1 + .../services/espanso-darwin/launchd.plist | 29 ++++++++++ 5 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 tests/modules/services/espanso-darwin/basic-configuration.nix create mode 100644 tests/modules/services/espanso-darwin/default.nix create mode 100644 tests/modules/services/espanso-darwin/launchd.plist diff --git a/modules/services/espanso.nix b/modules/services/espanso.nix index 404dfecd..a466b6f7 100644 --- a/modules/services/espanso.nix +++ b/modules/services/espanso.nix @@ -1,11 +1,9 @@ { pkgs, config, lib, ... }: let inherit (lib) - mkOption mkEnableOption mkIf maintainers literalExpression types platforms + mkOption mkEnableOption mkIf maintainers literalExpression types mkRemovedOptionModule versionAtLeast; - inherit (lib.hm.assertions) assertPlatform; - cfg = config.services.espanso; espansoVersion = cfg.package.version; @@ -99,15 +97,12 @@ in { }; config = mkIf cfg.enable { - assertions = [ - (assertPlatform "services.espanso" pkgs platforms.linux) - { - 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. + ''; + }]; home.packages = [ cfg.package ]; @@ -131,5 +126,20 @@ in { }; Install = { WantedBy = [ "default.target" ]; }; }; + + launchd.agents.espanso = { + enable = true; + config = { + ProgramArguments = [ "${cfg.package}/bin/espanso" "launcher" ]; + EnvironmentVariables.PATH = + "${cfg.package}/bin:/usr/bin:/bin:/usr/sbin:/sbin"; + KeepAlive = { + Crashed = true; + SuccessfulExit = false; + }; + ProcessType = "Background"; + RunAtLoad = true; + }; + }; }; } diff --git a/tests/default.nix b/tests/default.nix index 567b75d5..62538966 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -163,6 +163,7 @@ in import nmtSrc { ./modules/xresources ] ++ lib.optionals isDarwin [ ./modules/launchd + ./modules/services/espanso-darwin ./modules/services/git-sync-darwin ./modules/services/imapnotify-darwin ./modules/services/nix-gc-darwin diff --git a/tests/modules/services/espanso-darwin/basic-configuration.nix b/tests/modules/services/espanso-darwin/basic-configuration.nix new file mode 100644 index 00000000..4a2f2ee7 --- /dev/null +++ b/tests/modules/services/espanso-darwin/basic-configuration.nix @@ -0,0 +1,55 @@ +{ ... }: { + services.espanso = { + enable = true; + configs = { default = { show_notifications = false; }; }; + matches = { + base = { + matches = [ + { + trigger = ":now"; + replace = "It's {{currentdate}} {{currenttime}}"; + } + { + trigger = ":hello"; + replace = '' + line1 + line2''; + } + { + regex = ":hi(?P.*)\\."; + replace = "Hi {{person}}!"; + } + ]; + global_vars = [ + { + name = "currentdate"; + type = "date"; + params = { format = "%d/%m/%Y"; }; + } + { + name = "currenttime"; + type = "date"; + params = { format = "%R"; }; + } + ]; + }; + }; + }; + + test.stubs.espanso = { }; + + nmt.script = '' + serviceFile="LaunchAgents/org.nix-community.home.espanso.plist" + serviceFileNormalized="$(normalizeStorePaths "$serviceFile")" + assertFileExists $serviceFile + assertFileContent $serviceFileNormalized ${./launchd.plist} + + configFile=home-files/.config/espanso/config/default.yml + assertFileExists "$configFile" + assertFileContent "$configFile" ${../espanso/basic-configuration.yaml} + + matchFile=home-files/.config/espanso/match/base.yml + assertFileExists "$matchFile" + assertFileContent "$matchFile" ${../espanso/basic-matches.yaml} + ''; +} diff --git a/tests/modules/services/espanso-darwin/default.nix b/tests/modules/services/espanso-darwin/default.nix new file mode 100644 index 00000000..6acb2f8d --- /dev/null +++ b/tests/modules/services/espanso-darwin/default.nix @@ -0,0 +1 @@ +{ espanso-darwin-basic-configuration = ./basic-configuration.nix; } diff --git a/tests/modules/services/espanso-darwin/launchd.plist b/tests/modules/services/espanso-darwin/launchd.plist new file mode 100644 index 00000000..8cbc4af0 --- /dev/null +++ b/tests/modules/services/espanso-darwin/launchd.plist @@ -0,0 +1,29 @@ + + + + + EnvironmentVariables + + PATH + @espanso@/bin:/usr/bin:/bin:/usr/sbin:/sbin + + KeepAlive + + Crashed + + SuccessfulExit + + + Label + org.nix-community.home.espanso + ProcessType + Background + ProgramArguments + + @espanso@/bin/espanso + launcher + + RunAtLoad + + + \ No newline at end of file