2021-10-24 22:27:41 +00:00
|
|
|
{ pkgs, config, lib, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
2024-04-15 07:40:27 +00:00
|
|
|
mkOption mkEnableOption mkIf maintainers literalExpression types
|
2023-06-09 10:05:01 +00:00
|
|
|
mkRemovedOptionModule versionAtLeast;
|
2021-10-24 22:27:41 +00:00
|
|
|
|
|
|
|
cfg = config.services.espanso;
|
2023-06-09 10:05:01 +00:00
|
|
|
espansoVersion = cfg.package.version;
|
2021-10-24 22:27:41 +00:00
|
|
|
|
|
|
|
yaml = pkgs.formats.yaml { };
|
|
|
|
in {
|
2023-06-09 10:05:01 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "espanso" "settings" ]
|
|
|
|
"Use services.espanso.configs and services.espanso.matches instead.")
|
|
|
|
];
|
|
|
|
meta.maintainers = [
|
|
|
|
maintainers.lucasew
|
|
|
|
maintainers.bobvanderlinden
|
|
|
|
lib.hm.maintainers.liyangau
|
2024-05-16 22:03:33 +00:00
|
|
|
maintainers.n8henrie
|
2023-06-09 10:05:01 +00:00
|
|
|
];
|
2021-10-24 22:27:41 +00:00
|
|
|
options = {
|
|
|
|
services.espanso = {
|
2023-07-01 23:45:18 +00:00
|
|
|
enable = mkEnableOption "Espanso: cross platform text expander in Rust";
|
2021-10-24 22:27:41 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Which espanso package to use";
|
2021-10-24 22:27:41 +00:00
|
|
|
default = pkgs.espanso;
|
|
|
|
defaultText = literalExpression "pkgs.espanso";
|
|
|
|
};
|
|
|
|
|
2023-06-09 10:05:01 +00:00
|
|
|
configs = mkOption {
|
2021-10-24 22:27:41 +00:00
|
|
|
type = yaml.type;
|
2023-06-09 10:05:01 +00:00
|
|
|
default = { default = { }; };
|
2021-10-24 22:27:41 +00:00
|
|
|
example = literalExpression ''
|
|
|
|
{
|
2023-06-09 10:05:01 +00:00
|
|
|
default = {
|
|
|
|
show_notifications = false;
|
|
|
|
};
|
|
|
|
vscode = {
|
|
|
|
filter_title = "Visual Studio Code$";
|
|
|
|
backend = "Clipboard";
|
|
|
|
};
|
|
|
|
};
|
2021-10-24 22:27:41 +00:00
|
|
|
'';
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2021-10-24 22:27:41 +00:00
|
|
|
The Espanso configuration to use. See
|
2023-06-30 23:30:13 +00:00
|
|
|
<https://espanso.org/docs/configuration/basics/>
|
2023-06-09 10:05:01 +00:00
|
|
|
for a description of available options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
matches = mkOption {
|
|
|
|
type = yaml.type;
|
|
|
|
default = { default.matches = [ ]; };
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
base = {
|
|
|
|
matches = [
|
|
|
|
{
|
|
|
|
trigger = ":now";
|
|
|
|
replace = "It's {{currentdate}} {{currenttime}}";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
trigger = ":hello";
|
|
|
|
replace = "line1\nline2";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
regex = ":hi(?P<person>.*)\\.";
|
|
|
|
replace = "Hi {{person}}!";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
global_vars = {
|
|
|
|
global_vars = [
|
|
|
|
{
|
|
|
|
name = "currentdate";
|
|
|
|
type = "date";
|
|
|
|
params = {format = "%d/%m/%Y";};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "currenttime";
|
|
|
|
type = "date";
|
|
|
|
params = {format = "%R";};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2023-06-09 10:05:01 +00:00
|
|
|
The Espanso matches to use. See
|
2023-06-30 23:30:13 +00:00
|
|
|
<https://espanso.org/docs/matches/basics/>
|
2021-10-24 22:27:41 +00:00
|
|
|
for a description of available options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2024-04-15 07:40:27 +00:00
|
|
|
assertions = [{
|
|
|
|
assertion = versionAtLeast espansoVersion "2";
|
|
|
|
message = ''
|
|
|
|
The services.espanso module only supports Espanso version 2 or later.
|
|
|
|
'';
|
|
|
|
}];
|
2021-10-24 22:27:41 +00:00
|
|
|
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
2023-06-09 10:05:01 +00:00
|
|
|
xdg.configFile = let
|
|
|
|
configFiles = lib.mapAttrs' (name: value: {
|
|
|
|
name = "espanso/config/${name}.yml";
|
|
|
|
value = { source = yaml.generate "${name}.yml" value; };
|
|
|
|
}) cfg.configs;
|
|
|
|
matchesFiles = lib.mapAttrs' (name: value: {
|
|
|
|
name = "espanso/match/${name}.yml";
|
|
|
|
value = { source = yaml.generate "${name}.yml" value; };
|
|
|
|
}) cfg.matches;
|
|
|
|
in configFiles // matchesFiles;
|
2021-10-24 22:27:41 +00:00
|
|
|
|
|
|
|
systemd.user.services.espanso = {
|
|
|
|
Unit = { Description = "Espanso: cross platform text expander in Rust"; };
|
|
|
|
Service = {
|
|
|
|
Type = "exec";
|
|
|
|
ExecStart = "${cfg.package}/bin/espanso daemon";
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
Install = { WantedBy = [ "default.target" ]; };
|
|
|
|
};
|
2024-04-15 07:40:27 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
RunAtLoad = true;
|
|
|
|
};
|
|
|
|
};
|
2021-10-24 22:27:41 +00:00
|
|
|
};
|
|
|
|
}
|