1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-05 02:39:45 +01:00
home-manager/modules/services/espanso.nix
Emily 36a53d9f26 treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]. All
conversions were automatically checked to produce the same DocBook
result when converted back, modulo minor typographical/formatting
differences on the acceptable-to-desirable spectrum.

To reproduce this commit, run:

  $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
    nix shell nixpkgs#coreutils \
    -c find . -name '*.nix' \
    -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
    {} +
  $ ./format

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
2023-07-17 18:40:56 +01:00

136 lines
3.8 KiB
Nix

{ pkgs, config, lib, ... }:
let
inherit (lib)
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 {
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
(lib.mdDoc "Espanso: cross platform text expander in Rust");
package = mkOption {
type = types.package;
description = lib.mdDoc "Which espanso package to use";
default = pkgs.espanso;
defaultText = literalExpression "pkgs.espanso";
};
configs = mkOption {
type = yaml.type;
default = { default = { }; };
example = literalExpression ''
{
default = {
show_notifications = false;
};
vscode = {
filter_title = "Visual Studio Code$";
backend = "Clipboard";
};
};
'';
description = lib.mdDoc ''
The Espanso configuration to use. See
<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 = lib.mdDoc ''
The Espanso matches to use. See
<https://espanso.org/docs/matches/basics/>
for a description of available options.
'';
};
};
};
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.
'';
}
];
home.packages = [ cfg.package ];
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" ]; };
};
};
}