2021-10-24 22:27:41 +00:00
|
|
|
{ pkgs, config, lib, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
2023-06-09 10:05:01 +00:00
|
|
|
mkOption mkEnableOption mkIf maintainers literalExpression types platforms
|
|
|
|
mkRemovedOptionModule versionAtLeast;
|
2021-10-24 22:27:41 +00:00
|
|
|
|
|
|
|
inherit (lib.hm.assertions) assertPlatform;
|
|
|
|
|
|
|
|
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
|
|
|
|
];
|
2021-10-24 22:27:41 +00:00
|
|
|
options = {
|
|
|
|
services.espanso = {
|
2023-06-30 23:30:13 +00:00
|
|
|
enable = mkEnableOption
|
|
|
|
(lib.mdDoc "Espanso: cross platform text expander in Rust");
|
2021-10-24 22:27:41 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc "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-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
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-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
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 {
|
2023-06-09 10:05:01 +00:00
|
|
|
assertions = [
|
|
|
|
(assertPlatform "services.espanso" pkgs platforms.linux)
|
|
|
|
{
|
|
|
|
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" ]; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|