1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-01 00:39:45 +01:00
home-manager/modules/services/espanso.nix

136 lines
3.8 KiB
Nix
Raw Normal View History

{ pkgs, config, lib, ... }:
let
inherit (lib)
[23.05] backport #4066 (#4083) * tests: `--show-trace` in CI (#4070) (cherry picked from commit f889ec0ec366e3ad8fb94e3afa7a31f3ee1da3b9) * tests/stubs: inherit default versions from pkgs (#4069) * tests/stubs: inherit default versions from pkgs * tests/browserpass: temporarily disable on darwin The package currently fails to evaluate on darwin due to a nixpkgs problem: https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 (cherry picked from commit 69bdd6de50df2082901d94dbf70ecb762d8b636c) * 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> (cherry picked from commit 1e5d741ea3f3290d7ac06a02ded24bfdc7aadb37) --------- Co-authored-by: Li Yang <71299093+liyangau@users.noreply.github.com>
2023-06-12 17:05:45 +02:00
mkOption mkEnableOption mkIf maintainers literalExpression types platforms
mkRemovedOptionModule versionAtLeast;
inherit (lib.hm.assertions) assertPlatform;
cfg = config.services.espanso;
[23.05] backport #4066 (#4083) * tests: `--show-trace` in CI (#4070) (cherry picked from commit f889ec0ec366e3ad8fb94e3afa7a31f3ee1da3b9) * tests/stubs: inherit default versions from pkgs (#4069) * tests/stubs: inherit default versions from pkgs * tests/browserpass: temporarily disable on darwin The package currently fails to evaluate on darwin due to a nixpkgs problem: https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 (cherry picked from commit 69bdd6de50df2082901d94dbf70ecb762d8b636c) * 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> (cherry picked from commit 1e5d741ea3f3290d7ac06a02ded24bfdc7aadb37) --------- Co-authored-by: Li Yang <71299093+liyangau@users.noreply.github.com>
2023-06-12 17:05:45 +02:00
espansoVersion = cfg.package.version;
yaml = pkgs.formats.yaml { };
in {
[23.05] backport #4066 (#4083) * tests: `--show-trace` in CI (#4070) (cherry picked from commit f889ec0ec366e3ad8fb94e3afa7a31f3ee1da3b9) * tests/stubs: inherit default versions from pkgs (#4069) * tests/stubs: inherit default versions from pkgs * tests/browserpass: temporarily disable on darwin The package currently fails to evaluate on darwin due to a nixpkgs problem: https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 (cherry picked from commit 69bdd6de50df2082901d94dbf70ecb762d8b636c) * 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> (cherry picked from commit 1e5d741ea3f3290d7ac06a02ded24bfdc7aadb37) --------- Co-authored-by: Li Yang <71299093+liyangau@users.noreply.github.com>
2023-06-12 17:05:45 +02: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
];
options = {
services.espanso = {
enable = mkEnableOption "Espanso: cross platform text expander in Rust";
package = mkOption {
type = types.package;
description = "Which espanso package to use";
default = pkgs.espanso;
defaultText = literalExpression "pkgs.espanso";
};
[23.05] backport #4066 (#4083) * tests: `--show-trace` in CI (#4070) (cherry picked from commit f889ec0ec366e3ad8fb94e3afa7a31f3ee1da3b9) * tests/stubs: inherit default versions from pkgs (#4069) * tests/stubs: inherit default versions from pkgs * tests/browserpass: temporarily disable on darwin The package currently fails to evaluate on darwin due to a nixpkgs problem: https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 (cherry picked from commit 69bdd6de50df2082901d94dbf70ecb762d8b636c) * 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> (cherry picked from commit 1e5d741ea3f3290d7ac06a02ded24bfdc7aadb37) --------- Co-authored-by: Li Yang <71299093+liyangau@users.noreply.github.com>
2023-06-12 17:05:45 +02:00
configs = mkOption {
type = yaml.type;
[23.05] backport #4066 (#4083) * tests: `--show-trace` in CI (#4070) (cherry picked from commit f889ec0ec366e3ad8fb94e3afa7a31f3ee1da3b9) * tests/stubs: inherit default versions from pkgs (#4069) * tests/stubs: inherit default versions from pkgs * tests/browserpass: temporarily disable on darwin The package currently fails to evaluate on darwin due to a nixpkgs problem: https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 (cherry picked from commit 69bdd6de50df2082901d94dbf70ecb762d8b636c) * 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> (cherry picked from commit 1e5d741ea3f3290d7ac06a02ded24bfdc7aadb37) --------- Co-authored-by: Li Yang <71299093+liyangau@users.noreply.github.com>
2023-06-12 17:05:45 +02:00
default = { default = { }; };
example = literalExpression ''
{
[23.05] backport #4066 (#4083) * tests: `--show-trace` in CI (#4070) (cherry picked from commit f889ec0ec366e3ad8fb94e3afa7a31f3ee1da3b9) * tests/stubs: inherit default versions from pkgs (#4069) * tests/stubs: inherit default versions from pkgs * tests/browserpass: temporarily disable on darwin The package currently fails to evaluate on darwin due to a nixpkgs problem: https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 (cherry picked from commit 69bdd6de50df2082901d94dbf70ecb762d8b636c) * 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> (cherry picked from commit 1e5d741ea3f3290d7ac06a02ded24bfdc7aadb37) --------- Co-authored-by: Li Yang <71299093+liyangau@users.noreply.github.com>
2023-06-12 17:05:45 +02:00
default = {
show_notifications = false;
};
vscode = {
filter_title = "Visual Studio Code$";
backend = "Clipboard";
};
};
'';
description = ''
The Espanso configuration to use. See
[23.05] backport #4066 (#4083) * tests: `--show-trace` in CI (#4070) (cherry picked from commit f889ec0ec366e3ad8fb94e3afa7a31f3ee1da3b9) * tests/stubs: inherit default versions from pkgs (#4069) * tests/stubs: inherit default versions from pkgs * tests/browserpass: temporarily disable on darwin The package currently fails to evaluate on darwin due to a nixpkgs problem: https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 (cherry picked from commit 69bdd6de50df2082901d94dbf70ecb762d8b636c) * 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> (cherry picked from commit 1e5d741ea3f3290d7ac06a02ded24bfdc7aadb37) --------- Co-authored-by: Li Yang <71299093+liyangau@users.noreply.github.com>
2023-06-12 17:05:45 +02:00
<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.
'';
};
};
};
config = mkIf cfg.enable {
[23.05] backport #4066 (#4083) * tests: `--show-trace` in CI (#4070) (cherry picked from commit f889ec0ec366e3ad8fb94e3afa7a31f3ee1da3b9) * tests/stubs: inherit default versions from pkgs (#4069) * tests/stubs: inherit default versions from pkgs * tests/browserpass: temporarily disable on darwin The package currently fails to evaluate on darwin due to a nixpkgs problem: https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 (cherry picked from commit 69bdd6de50df2082901d94dbf70ecb762d8b636c) * 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> (cherry picked from commit 1e5d741ea3f3290d7ac06a02ded24bfdc7aadb37) --------- Co-authored-by: Li Yang <71299093+liyangau@users.noreply.github.com>
2023-06-12 17:05:45 +02:00
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 ];
[23.05] backport #4066 (#4083) * tests: `--show-trace` in CI (#4070) (cherry picked from commit f889ec0ec366e3ad8fb94e3afa7a31f3ee1da3b9) * tests/stubs: inherit default versions from pkgs (#4069) * tests/stubs: inherit default versions from pkgs * tests/browserpass: temporarily disable on darwin The package currently fails to evaluate on darwin due to a nixpkgs problem: https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 (cherry picked from commit 69bdd6de50df2082901d94dbf70ecb762d8b636c) * 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> (cherry picked from commit 1e5d741ea3f3290d7ac06a02ded24bfdc7aadb37) --------- Co-authored-by: Li Yang <71299093+liyangau@users.noreply.github.com>
2023-06-12 17:05:45 +02: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;
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" ]; };
};
};
}