1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

espanso: enable module on darwin

This commit is contained in:
Nathan Henrie 2024-04-15 01:40:27 -06:00 committed by GitHub
parent 9f32c66a51
commit 59d50bc582
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 108 additions and 12 deletions

View file

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

View file

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

View file

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

View file

@ -0,0 +1 @@
{ espanso-darwin-basic-configuration = ./basic-configuration.nix; }

View file

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