1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-30 15:09:46 +01:00

[23.05] backport #4066 (#4083)

* tests: `--show-trace` in CI (#4070)

(cherry picked from commit f889ec0ec3)

* 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 69bdd6de50)

* 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 1e5d741ea3)

---------

Co-authored-by: Li Yang <71299093+liyangau@users.noreply.github.com>
This commit is contained in:
Naïm Favier 2023-06-12 17:05:45 +02:00 committed by GitHub
parent 93db05480c
commit e753d659c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 160 additions and 86 deletions

View file

@ -24,7 +24,7 @@ jobs:
echo "Error: literalExample should be replaced by literalExpression" > /dev/stderr echo "Error: literalExample should be replaced by literalExpression" > /dev/stderr
exit 1 exit 1
fi fi
- run: nix-build -A docs.jsonModuleMaintainers - run: nix-build --show-trace -A docs.jsonModuleMaintainers
- run: ./format -c - run: ./format -c
- run: nix-shell . -A install - run: nix-shell --show-trace . -A install
- run: nix-shell --arg enableBig false --pure tests -A run.all - run: nix-shell --show-trace --arg enableBig false --pure tests -A run.all

View file

@ -394,4 +394,10 @@
github = "natecox"; github = "natecox";
githubId = 2782695; githubId = 2782695;
}; };
liyangau = {
name = "Li Yang";
email = "d@aufomm.com";
github = "liyangau";
githubId = 71299093;
};
} }

View file

@ -1,19 +1,25 @@
{ pkgs, config, lib, ... }: { pkgs, config, lib, ... }:
let let
inherit (lib) inherit (lib)
mkOption mkEnableOption mkIf maintainers literalExpression types platforms; mkOption mkEnableOption mkIf maintainers literalExpression types platforms
mkRemovedOptionModule versionAtLeast;
inherit (lib.hm.assertions) assertPlatform; inherit (lib.hm.assertions) assertPlatform;
cfg = config.services.espanso; cfg = config.services.espanso;
espansoVersion = cfg.package.version;
yaml = pkgs.formats.yaml { }; yaml = pkgs.formats.yaml { };
in { 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 = { options = {
services.espanso = { services.espanso = {
enable = mkEnableOption "Espanso: cross platform text expander in Rust"; enable = mkEnableOption "Espanso: cross platform text expander in Rust";
@ -25,40 +31,67 @@ in {
defaultText = literalExpression "pkgs.espanso"; defaultText = literalExpression "pkgs.espanso";
}; };
settings = mkOption { configs = mkOption {
type = yaml.type; type = yaml.type;
default = { matches = [ ]; }; default = { default = { }; };
example = literalExpression '' example = literalExpression ''
{ {
matches = [ default = {
{ # Simple text replacement show_notifications = false;
trigger = ":espanso"; };
replace = "Hi there!"; vscode = {
} filter_title = "Visual Studio Code$";
{ # Dates backend = "Clipboard";
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"; };
}];
}
];
}
''; '';
description = '' description = ''
The Espanso configuration to use. See 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. for a description of available options.
''; '';
}; };
@ -66,12 +99,28 @@ in {
}; };
config = mkIf cfg.enable { 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 ]; home.packages = [ cfg.package ];
xdg.configFile."espanso/default.yml".source = xdg.configFile = let
yaml.generate "espanso-default.yml" cfg.settings; 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 = { systemd.user.services.espanso = {
Unit = { Description = "Espanso: cross platform text expander in Rust"; }; Unit = { Description = "Espanso: cross platform text expander in Rust"; };

View file

@ -64,7 +64,6 @@ import nmt {
./modules/programs/bat ./modules/programs/bat
./modules/programs/bottom ./modules/programs/bottom
./modules/programs/broot ./modules/programs/broot
./modules/programs/browserpass
./modules/programs/btop ./modules/programs/btop
./modules/programs/dircolors ./modules/programs/dircolors
./modules/programs/direnv ./modules/programs/direnv
@ -155,6 +154,7 @@ import nmt {
./modules/programs/autorandr ./modules/programs/autorandr
./modules/programs/beets # One test relies on services.mpd ./modules/programs/beets # One test relies on services.mpd
./modules/programs/borgmatic ./modules/programs/borgmatic
./modules/programs/browserpass # TODO re-enable on Darwin when https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 is fixed
./modules/programs/firefox ./modules/programs/firefox
./modules/programs/foot ./modules/programs/foot
./modules/programs/fuzzel ./modules/programs/fuzzel

View file

@ -3,31 +3,38 @@
{ {
services.espanso = { services.espanso = {
enable = true; enable = true;
settings = { configs = { default = { show_notifications = false; }; };
matches = {
base = {
matches = [ matches = [
{ # Simple text replacement {
trigger = ":espanso"; trigger = ":now";
replace = "Hi there!"; replace = "It's {{currentdate}} {{currenttime}}";
} }
{ # Dates {
trigger = ":date"; trigger = ":hello";
replace = "{{mydate}}"; replace = ''
vars = [{ line1
name = "mydate"; line2'';
type = "date";
params = { format = "%m/%d/%Y"; };
}];
} }
{ # Shell commands {
trigger = ":shell"; regex = ":hi(?P<person>.*)\\.";
replace = "{{output}}"; replace = "Hi {{person}}!";
vars = [{
name = "output";
type = "shell";
params = { cmd = "echo Hello from your shell"; };
}];
} }
]; ];
global_vars = [
{
name = "currentdate";
type = "date";
params = { format = "%d/%m/%Y"; };
}
{
name = "currenttime";
type = "date";
params = { format = "%R"; };
}
];
};
}; };
}; };
@ -38,8 +45,12 @@
assertFileExists "$serviceFile" assertFileExists "$serviceFile"
assertFileContent "$serviceFile" ${./basic-configuration.service} assertFileContent "$serviceFile" ${./basic-configuration.service}
configFile=home-files/.config/espanso/default.yml configFile=home-files/.config/espanso/config/default.yml
assertFileExists "$configFile" assertFileExists "$configFile"
assertFileContent "$configFile" ${./basic-configuration.yaml} assertFileContent "$configFile" ${./basic-configuration.yaml}
matchFile=home-files/.config/espanso/match/base.yml
assertFileExists "$matchFile"
assertFileContent "$matchFile" ${./basic-matches.yaml}
''; '';
} }

View file

@ -1,17 +1 @@
matches: show_notifications: false
- replace: Hi there!
trigger: :espanso
- replace: '{{mydate}}'
trigger: :date
vars:
- name: mydate
params:
format: '%m/%d/%Y'
type: date
- replace: '{{output}}'
trigger: :shell
vars:
- name: output
params:
cmd: echo Hello from your shell
type: shell

View file

@ -0,0 +1,18 @@
global_vars:
- name: currentdate
params:
format: '%d/%m/%Y'
type: date
- name: currenttime
params:
format: '%R'
type: date
matches:
- replace: It's {{currentdate}} {{currenttime}}
trigger: :now
- replace: 'line1
line2'
trigger: :hello
- regex: :hi(?P<person>.*)\.
replace: Hi {{person}}!

View file

@ -15,12 +15,13 @@ let
outPath = mkOption { outPath = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = "@${name}@"; default = "@${name}@";
defaultText = "@\${name}@"; defaultText = literalExpression ''"@''${name}@"'';
}; };
version = mkOption { version = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = null; default = null;
defaultText = literalExpression "pkgs.\${name}.version or null";
}; };
buildScript = mkOption { buildScript = mkOption {
@ -55,7 +56,12 @@ in {
config = { config = {
lib.test.mkStubPackage = mkStubPackage; lib.test.mkStubPackage = mkStubPackage;
nixpkgs.overlays = mkIf (config.test.stubs != { }) nixpkgs.overlays = mkIf (config.test.stubs != { }) [
[ (self: super: mapAttrs (n: mkStubPackage) config.test.stubs) ]; (self: super:
mapAttrs (n: v:
mkStubPackage (v // optionalAttrs (v.version == null) {
version = super.${n}.version or null;
})) config.test.stubs)
];
}; };
} }