Skip to content

Commit

Permalink
espanso: enable module on darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
n8henrie authored Apr 15, 2024
1 parent 9f32c66 commit 59d50bc
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 12 deletions.
34 changes: 22 additions & 12 deletions modules/services/espanso.nix
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 ];

Expand All @@ -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;
};
};
};
}
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions tests/modules/services/espanso-darwin/basic-configuration.nix
Original file line number Diff line number Diff line change
@@ -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<person>.*)\\.";
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}
'';
}
1 change: 1 addition & 0 deletions tests/modules/services/espanso-darwin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ espanso-darwin-basic-configuration = ./basic-configuration.nix; }
29 changes: 29 additions & 0 deletions tests/modules/services/espanso-darwin/launchd.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>@espanso@/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>KeepAlive</key>
<dict>
<key>Crashed</key>
<true/>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>org.nix-community.home.espanso</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>@espanso@/bin/espanso</string>
<string>launcher</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

0 comments on commit 59d50bc

Please sign in to comment.