1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-14 21:11:08 +01:00

Espanso: Fix broken module to be compatible with Espanso version 2.x (#4066)

* Fix espanso module to work with 2.x version

* espanso: fix espanso module

This module is currently broken. It does not create `config` and `match` folders which are required by espanso 2.x version.

This PR fixed this issue and support creating multiple files under `config` and
`match` folder.

* Espanso: fix espanso module

This module is currently broken. It does not create `config` and `match` folders which are required by espanso 2.x version.

This PR fixed this issue and support creating multiple files under `config` and `match` folder.

Add descriptions

* Add versionAtLeast and mkRemovedOptionModule

* Correct maintainers list

* remove config key from example

* format basic-configuration.nix

* Update modules/services/espanso.nix

Co-authored-by: Naïm Favier <n@monade.li>

* fix maintainers list

---------

Co-authored-by: Naïm Favier <n@monade.li>
This commit is contained in:
Li Yang 2023-06-09 20:05:01 +10:00 committed by GitHub
parent 9b8ba302ff
commit 1e5d741ea3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 147 additions and 79 deletions

View file

@ -1,19 +1,25 @@
{ pkgs, config, lib, ... }:
let
inherit (lib)
mkOption mkEnableOption mkIf maintainers literalExpression types platforms;
mkOption mkEnableOption mkIf maintainers literalExpression types platforms
mkRemovedOptionModule versionAtLeast;
inherit (lib.hm.assertions) assertPlatform;
cfg = config.services.espanso;
espansoVersion = cfg.package.version;
yaml = pkgs.formats.yaml { };
in {
meta.maintainers = with maintainers; [ lucasew ];
imports = [
(mkRemovedOptionModule [ "services" "espanso" "settings" ]
"Use services.espanso.configs and services.espanso.matches instead.")
];
meta.maintainers = [
maintainers.lucasew
maintainers.bobvanderlinden
lib.hm.maintainers.liyangau
];
options = {
services.espanso = {
enable = mkEnableOption "Espanso: cross platform text expander in Rust";
@ -25,40 +31,67 @@ in {
defaultText = literalExpression "pkgs.espanso";
};
settings = mkOption {
configs = mkOption {
type = yaml.type;
default = { matches = [ ]; };
default = { default = { }; };
example = literalExpression ''
{
matches = [
{ # Simple text replacement
trigger = ":espanso";
replace = "Hi there!";
}
{ # Dates
trigger = ":date";
replace = "{{mydate}}";
vars = [{
name = "mydate";
type = "date";
params = { format = "%m/%d/%Y"; };
}];
}
{ # Shell commands
trigger = ":shell";
replace = "{{output}}";
vars = [{
name = "output";
type = "shell";
params = { cmd = "echo Hello from your shell"; };
}];
}
];
}
default = {
show_notifications = false;
};
vscode = {
filter_title = "Visual Studio Code$";
backend = "Clipboard";
};
};
'';
description = ''
The Espanso configuration to use. See
<link xlink:href="https://espanso.org/docs/configuration/"/>
<link xlink:href="https://espanso.org/docs/configuration/basics/"/>
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";};
}
];
};
};
'';
description = ''
The Espanso matches to use. See
<link xlink:href="https://espanso.org/docs/matches/basics/"/>
for a description of available options.
'';
};
@ -66,12 +99,28 @@ in {
};
config = mkIf cfg.enable {
assertions = [ (assertPlatform "services.espanso" pkgs platforms.linux) ];
assertions = [
(assertPlatform "services.espanso" pkgs platforms.linux)
{
assertion = versionAtLeast espansoVersion "2";
message = ''
The services.espanso module only supports Espanso version 2 or later.
'';
}
];
home.packages = [ cfg.package ];
xdg.configFile."espanso/default.yml".source =
yaml.generate "espanso-default.yml" cfg.settings;
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;
systemd.user.services.espanso = {
Unit = { Description = "Espanso: cross platform text expander in Rust"; };