Skip to content

Commit 9d076b0

Browse files
committed
tests/plugins-by-name: simplify by-name-enable-opts impl
Instead of using a regex to match the absolute file path, remove the nixvim root path prefix.
1 parent 09b736b commit 9d076b0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tests/plugins-by-name.nix

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
runCommandLocal,
66
}:
77
let
8+
nixvim-root = ../.;
89
by-name = ../plugins/by-name;
910
options = lib.collect lib.isOption nixvimConfiguration.options;
1011

12+
toRelative = lib.removePrefix (toString nixvim-root);
13+
1114
# Option namespace expect by-name plugins to use
1215
namespace = "plugins";
1316

@@ -30,15 +33,16 @@ let
3033
# Find plugins by looking for `*.*.enable` options that are declared in `plugins/by-name`
3134
by-name-enable-opts =
3235
let
33-
regex = ''/nix/store/[^/]+/plugins/by-name/(.*)'';
3436
optionalPair =
3537
opt: file:
3638
let
37-
result = builtins.match regex file;
38-
in
39-
lib.optional (result != null) {
39+
relative = toRelative file;
4040
# Use the file name relative to `plugins/by-name/`
41-
name = builtins.head result;
41+
name = lib.removePrefix "plugins/by-name/" relative;
42+
hasPrefix = name != relative;
43+
in
44+
lib.optional hasPrefix {
45+
inherit name;
4246
# Use only the first two parts of the option location
4347
value = lib.genList (builtins.elemAt opt.loc) 2;
4448
};

0 commit comments

Comments
 (0)