From 5ccc3d6739b5e694841ced27cb5c06b50b163695 Mon Sep 17 00:00:00 2001 From: lordkekz Date: Mon, 3 Jun 2024 19:39:00 +0200 Subject: [PATCH 1/5] yazi: Ensure plugin suffix `.yazi` - Append suffix `.yazi` to symlink targets of yazi plugins, if needed - Improve some docs, especially links to upstream docs. - Update tests to make use of this feature. --- modules/programs/yazi.nix | 29 +++++++++++++++++------- tests/modules/programs/yazi/settings.nix | 7 +++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index 11f4e75cf..f96a9bdfa 100644 --- a/modules/programs/yazi.nix +++ b/modules/programs/yazi.nix @@ -144,9 +144,10 @@ in { type = with types; attrsOf (oneOf [ path package ]); default = { }; description = '' - Lua plugins. + Lua plugins. Will be linked into {file}`$XDG_CONFIG_HOME/yazi/plugins/`. - See https://yazi-rs.github.io/docs/plugins/overview/ for documentation. + See + for documentation. ''; example = literalExpression '' { @@ -162,7 +163,7 @@ in { description = '' Pre-made themes. - See https://yazi-rs.github.io/docs/flavors/overview/ for documentation. + See for documentation. ''; example = literalExpression '' { @@ -171,7 +172,6 @@ in { } ''; }; - }; config = mkIf cfg.enable { @@ -199,9 +199,22 @@ in { }; "yazi/init.lua" = mkIf (cfg.initLua != null) { source = cfg.initLua; }; } // (mapAttrs' - (name: value: nameValuePair "yazi/plugins/${name}" { source = value; }) - cfg.plugins) // (mapAttrs' - (name: value: nameValuePair "yazi/flavors/${name}" { source = value; }) - cfg.flavors); + (name: value: nameValuePair "yazi/flavors/${name}" { source = value; }) + cfg.flavors) // (let + # Make sure that the directory ends in `.yazi`, to comply with specification. + # `pluginName` is essential, it's needed to apply config in yazi's `init.lua` + ensureSuffix = pluginName: + if lib.hasSuffix ".yazi" pluginName then + "yazi/plugins/${pluginName}" + else + "yazi/plugins/${pluginName}.yazi"; + + mkPluginLink = pluginName: pluginPackage: { + name = ensureSuffix pluginName; + value.source = pluginPackage; + }; + + pluginLinks = mapAttrs' mkPluginLink cfg.plugins; + in pluginLinks); }; } diff --git a/tests/modules/programs/yazi/settings.nix b/tests/modules/programs/yazi/settings.nix index 4655ae8b3..33b99c2c5 100644 --- a/tests/modules/programs/yazi/settings.nix +++ b/tests/modules/programs/yazi/settings.nix @@ -70,7 +70,10 @@ }; }; initLua = ./init.lua; - plugins = { "test.yazi" = ./plugin; }; + plugins = { + "test.yazi" = ./plugin; + "anotherTest" = ./plugin; + }; flavors = { "test.yazi" = ./flavor; }; }; @@ -87,6 +90,8 @@ ${./init.lua} assertFileContent home-files/.config/yazi/plugins/test.yazi/init.lua \ ${./plugin/init.lua} + assertFileContent home-files/.config/yazi/plugins/anotherTest.yazi/init.lua \ + ${./plugin/init.lua} assertFileContent home-files/.config/yazi/flavors/test.yazi/init.lua \ ${./flavor/init.lua} ''; From 340b98c0abb56ae24d7ee7dee64104583ad8a8c6 Mon Sep 17 00:00:00 2001 From: lordkekz Date: Mon, 3 Jun 2024 20:29:06 +0200 Subject: [PATCH 2/5] yazi: Assert that plugins have valid structure --- modules/programs/yazi.nix | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index f96a9bdfa..59443dd31 100644 --- a/modules/programs/yazi.nix +++ b/modules/programs/yazi.nix @@ -209,12 +209,31 @@ in { else "yazi/plugins/${pluginName}.yazi"; - mkPluginLink = pluginName: pluginPackage: { + mkPluginLink = pluginName: pluginPackageOrPath: { name = ensureSuffix pluginName; - value.source = pluginPackage; + value.source = pluginPackageOrPath; }; pluginLinks = mapAttrs' mkPluginLink cfg.plugins; in pluginLinks); + + assertions = (mapAttrsToList (pluginName: pluginPackageOrPath: + let + isDir = pathIsDirectory "${pluginPackageOrPath}"; + hasInitLua = pathExists "${pluginPackageOrPath}/init.lua" + && !(pathIsDirectory "${pluginPackageOrPath}/init.lua"); + in { + assertion = isDir && hasInitLua; + message = + "Value at `programs.yazi.plugins.${pluginName}` is not a valid yazi plugin." + + (optionalString (!isDir) '' + + The path or package should be a directory, not a single file.'') + + (optionalString (!hasInitLua) '' + + The path or package must contain a file `init.lua`.'') + '' + + Evaluated value: `${pluginPackageOrPath}`''; + }) cfg.plugins); }; } From 09bc5c5949c73cf6b217badaae25feb2b4a7a2e5 Mon Sep 17 00:00:00 2001 From: Didn't read the style guide <50516935+lordkekz@users.noreply.github.com> Date: Tue, 4 Jun 2024 00:56:08 +0200 Subject: [PATCH 3/5] yazi: plugin names should be in kebab case (test) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: δΈ‰ε’²ι›… Β· Misaki Masa --- tests/modules/programs/yazi/settings.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/modules/programs/yazi/settings.nix b/tests/modules/programs/yazi/settings.nix index 33b99c2c5..f0d54faed 100644 --- a/tests/modules/programs/yazi/settings.nix +++ b/tests/modules/programs/yazi/settings.nix @@ -71,8 +71,8 @@ }; initLua = ./init.lua; plugins = { - "test.yazi" = ./plugin; - "anotherTest" = ./plugin; + "test" = ./plugin; + "another-test" = ./plugin; }; flavors = { "test.yazi" = ./flavor; }; }; From 16f86c94ce2399ae09ae99b8f071f37bbc964b4f Mon Sep 17 00:00:00 2001 From: lordkekz Date: Wed, 5 Jun 2024 21:24:18 +0200 Subject: [PATCH 4/5] yazi: Assert plugin/flavor structure and warn about plugin/flavor suffix - Always append suffix `.yazi` to plugin's and flavor's attribute names. - Warn if the attribute names already have the suffix. - Assert that plugin's and flavor's values point to directories containing an `init.lua` file. --- modules/programs/yazi.nix | 86 +++++++++++++--------- tests/modules/programs/yazi/empty/.gitkeep | 0 tests/modules/programs/yazi/settings.nix | 23 ++++-- 3 files changed, 66 insertions(+), 43 deletions(-) create mode 100644 tests/modules/programs/yazi/empty/.gitkeep diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index 59443dd31..db946344e 100644 --- a/modules/programs/yazi.nix +++ b/modules/programs/yazi.nix @@ -144,7 +144,9 @@ in { type = with types; attrsOf (oneOf [ path package ]); default = { }; description = '' - Lua plugins. Will be linked into {file}`$XDG_CONFIG_HOME/yazi/plugins/`. + Lua plugins. + Values should be a package or path containing an `init.lua` file. + Will be linked to {file}`$XDG_CONFIG_HOME/yazi/plugins/.yazi`. See for documentation. @@ -162,6 +164,8 @@ in { default = { }; description = '' Pre-made themes. + Values should be a package or path containing an `init.lua` file. + Will be linked to {file}`$XDG_CONFIG_HOME/yazi/flavors/.yazi`. See for documentation. ''; @@ -198,42 +202,52 @@ in { source = tomlFormat.generate "yazi-theme" cfg.theme; }; "yazi/init.lua" = mkIf (cfg.initLua != null) { source = cfg.initLua; }; - } // (mapAttrs' - (name: value: nameValuePair "yazi/flavors/${name}" { source = value; }) - cfg.flavors) // (let - # Make sure that the directory ends in `.yazi`, to comply with specification. - # `pluginName` is essential, it's needed to apply config in yazi's `init.lua` - ensureSuffix = pluginName: - if lib.hasSuffix ".yazi" pluginName then - "yazi/plugins/${pluginName}" - else - "yazi/plugins/${pluginName}.yazi"; + } // (mapAttrs' (name: value: + nameValuePair "yazi/flavors/${name}.yazi" { source = value; }) + cfg.flavors) // (mapAttrs' (name: value: + nameValuePair "yazi/plugins/${name}.yazi" { source = value; }) + cfg.plugins); - mkPluginLink = pluginName: pluginPackageOrPath: { - name = ensureSuffix pluginName; - value.source = pluginPackageOrPath; - }; + warnings = filter (s: s != "") (concatLists [ + (mapAttrsToList (name: value: + optionalString (hasSuffix ".yazi" name) '' + Flavors like `programs.yazi.flavors."${name}"` should no longer have the suffix ".yazi" in their attribute name. + The flavor will be linked to `$XDG_CONFIG_HOME/yazi/flavors/${name}.yazi`. + You probably want to rename it to `programs.yazi.flavors."${ + removeSuffix ".yazi" name + }"`. + '') cfg.flavors) + (mapAttrsToList (name: value: + optionalString (hasSuffix ".yazi" name) '' + Plugins like `programs.yazi.plugins."${name}"` should no longer have the suffix ".yazi" in their attribute name. + The plugin will be linked to `$XDG_CONFIG_HOME/yazi/plugins/${name}.yazi`. + You probably want to rename it to `programs.yazi.plugins."${ + removeSuffix ".yazi" name + }"`. + '') cfg.plugins) + ]); - pluginLinks = mapAttrs' mkPluginLink cfg.plugins; - in pluginLinks); - - assertions = (mapAttrsToList (pluginName: pluginPackageOrPath: - let - isDir = pathIsDirectory "${pluginPackageOrPath}"; - hasInitLua = pathExists "${pluginPackageOrPath}/init.lua" - && !(pathIsDirectory "${pluginPackageOrPath}/init.lua"); - in { - assertion = isDir && hasInitLua; - message = - "Value at `programs.yazi.plugins.${pluginName}` is not a valid yazi plugin." - + (optionalString (!isDir) '' - - The path or package should be a directory, not a single file.'') - + (optionalString (!hasInitLua) '' - - The path or package must contain a file `init.lua`.'') + '' - - Evaluated value: `${pluginPackageOrPath}`''; - }) cfg.plugins); + assertions = let + mkAsserts = opt: + mapAttrsToList (name: value: + let + isDir = pathIsDirectory "${value}"; + msgNotDir = optionalString (!isDir) + "The path or package should be a directory, not a single file."; + hasInitLua = pathExists "${value}/init.lua" + && !(pathIsDirectory "${value}/init.lua"); + msgNoInitLua = optionalString (!hasInitLua) + "The path or package must contain a file `init.lua`."; + singularOpt = removeSuffix "s" opt; + in { + assertion = isDir && hasInitLua; + message = '' + Value at `programs.yazi.${opt}.${name}` is not a valid yazi ${singularOpt}. + ${msgNotDir} + ${msgNoInitLua} + Evaluated value: `${value}` + ''; + }) cfg.${opt}; + in (mkAsserts "flavors") ++ (mkAsserts "plugins"); }; } diff --git a/tests/modules/programs/yazi/empty/.gitkeep b/tests/modules/programs/yazi/empty/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/modules/programs/yazi/settings.nix b/tests/modules/programs/yazi/settings.nix index f0d54faed..667038719 100644 --- a/tests/modules/programs/yazi/settings.nix +++ b/tests/modules/programs/yazi/settings.nix @@ -71,10 +71,21 @@ }; initLua = ./init.lua; plugins = { - "test" = ./plugin; - "another-test" = ./plugin; + testplugin = ./plugin; + ## Produces warning + #"plugin-with-suffix.yazi" = ./plugin; + ## Fails assertion + #single-file-plugin = ./plugin/init.lua; + #empty-dir-plugin = ./empty; + }; + flavors = { + testflavor = ./flavor; + ## Produces warning + #"flavor-with-suffix.yazi" = ./flavor; + ## Fails assertion + #single-file-flavor = ./flavor/init.lua; + #empty-dir-flavor = ./empty; }; - flavors = { "test.yazi" = ./flavor; }; }; test.stubs.yazi = { }; @@ -88,11 +99,9 @@ ${./theme-expected.toml} assertFileContent home-files/.config/yazi/init.lua \ ${./init.lua} - assertFileContent home-files/.config/yazi/plugins/test.yazi/init.lua \ + assertFileContent home-files/.config/yazi/plugins/testplugin.yazi/init.lua \ ${./plugin/init.lua} - assertFileContent home-files/.config/yazi/plugins/anotherTest.yazi/init.lua \ - ${./plugin/init.lua} - assertFileContent home-files/.config/yazi/flavors/test.yazi/init.lua \ + assertFileContent home-files/.config/yazi/flavors/testflavor.yazi/init.lua \ ${./flavor/init.lua} ''; } From 216d51eb22f9ce1a4c50a4737a4adcdb42fb6306 Mon Sep 17 00:00:00 2001 From: lordkekz Date: Thu, 6 Jun 2024 12:05:28 +0200 Subject: [PATCH 5/5] yazi: Fix expected structure of flavors --- modules/programs/yazi.nix | 29 +++++++---- tests/modules/programs/yazi/flavor/LICENSE | 0 .../programs/yazi/flavor/LICENSE-tmtheme | 0 tests/modules/programs/yazi/flavor/README.md | 50 +++++++++++++++++++ .../modules/programs/yazi/flavor/flavor.toml | 2 + tests/modules/programs/yazi/flavor/init.lua | 1 - .../modules/programs/yazi/flavor/preview.png | 0 .../modules/programs/yazi/flavor/tmtheme.xml | 0 tests/modules/programs/yazi/settings.nix | 6 +-- 9 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 tests/modules/programs/yazi/flavor/LICENSE create mode 100644 tests/modules/programs/yazi/flavor/LICENSE-tmtheme create mode 100644 tests/modules/programs/yazi/flavor/README.md create mode 100644 tests/modules/programs/yazi/flavor/flavor.toml delete mode 100644 tests/modules/programs/yazi/flavor/init.lua create mode 100644 tests/modules/programs/yazi/flavor/preview.png create mode 100644 tests/modules/programs/yazi/flavor/tmtheme.xml diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index db946344e..cb00ecc3a 100644 --- a/modules/programs/yazi.nix +++ b/modules/programs/yazi.nix @@ -164,7 +164,7 @@ in { default = { }; description = '' Pre-made themes. - Values should be a package or path containing an `init.lua` file. + Values should be a package or path containing the required files. Will be linked to {file}`$XDG_CONFIG_HOME/yazi/flavors/.yazi`. See for documentation. @@ -228,26 +228,37 @@ in { ]); assertions = let - mkAsserts = opt: + mkAsserts = opt: requiredFiles: mapAttrsToList (name: value: let isDir = pathIsDirectory "${value}"; msgNotDir = optionalString (!isDir) "The path or package should be a directory, not a single file."; - hasInitLua = pathExists "${value}/init.lua" - && !(pathIsDirectory "${value}/init.lua"); - msgNoInitLua = optionalString (!hasInitLua) - "The path or package must contain a file `init.lua`."; + isFileMissing = file: + !(pathExists "${value}/${file}") + || pathIsDirectory "${value}/${file}"; + missingFiles = filter isFileMissing requiredFiles; + msgFilesMissing = optionalString (missingFiles != [ ]) + "The ${singularOpt} is missing these files: ${ + toString missingFiles + }"; singularOpt = removeSuffix "s" opt; in { - assertion = isDir && hasInitLua; + assertion = isDir && missingFiles == [ ]; message = '' Value at `programs.yazi.${opt}.${name}` is not a valid yazi ${singularOpt}. ${msgNotDir} - ${msgNoInitLua} + ${msgFilesMissing} Evaluated value: `${value}` ''; }) cfg.${opt}; - in (mkAsserts "flavors") ++ (mkAsserts "plugins"); + in (mkAsserts "flavors" [ + "flavor.toml" + "tmtheme.xml" + "README.md" + "preview.png" + "LICENSE" + "LICENSE-tmtheme" + ]) ++ (mkAsserts "plugins" [ "init.lua" ]); }; } diff --git a/tests/modules/programs/yazi/flavor/LICENSE b/tests/modules/programs/yazi/flavor/LICENSE new file mode 100644 index 000000000..e69de29bb diff --git a/tests/modules/programs/yazi/flavor/LICENSE-tmtheme b/tests/modules/programs/yazi/flavor/LICENSE-tmtheme new file mode 100644 index 000000000..e69de29bb diff --git a/tests/modules/programs/yazi/flavor/README.md b/tests/modules/programs/yazi/flavor/README.md new file mode 100644 index 000000000..3ba41d0db --- /dev/null +++ b/tests/modules/programs/yazi/flavor/README.md @@ -0,0 +1,50 @@ +
+ Yazi logo +
+ +

+ Example Flavor for Yazi +

+ +## Cooking up a new flavor + +> [!NOTE] +> Please remove this section from your README before publishing. + +1. [x] Fork this repository and rename it to `your-flavor-name.yazi`. +2. [ ] Copy the **parts you need to customize** from the [default theme.toml](https://github.com/sxyazi/yazi/blob/main/yazi-config/preset/theme.toml) as `./flavor.toml`, and change them to meet your preferences. +3. [ ] Find a `.tmTheme` file on GitHub that matches the color of your flavor, copy it and it's license file as `./tmtheme.xml`, and `LICENSE-tmtheme`. +4. [ ] Modify the content and preview image in the README to fit your flavor. + +## πŸ‘€ Preview + + + +## 🎨 Installation + + + +```bash +# Linux/macOS +git clone https://github.com/username/example.yazi.git ~/.config/yazi/flavors/example.yazi + +# Windows +git clone https://github.com/username/example.yazi.git %AppData%\yazi\config\flavors\example.yazi +``` + +## βš™οΈ Usage + +Add the these lines to your `theme.toml` configuration file to use it: + + + +```toml +[flavor] +use = "example" +``` + +## πŸ“œ License + +The flavor is MIT-licensed, and the included tmTheme is also MIT-licensed. + +Check the [LICENSE](LICENSE) and [LICENSE-tmtheme](LICENSE-tmtheme) file for more details. diff --git a/tests/modules/programs/yazi/flavor/flavor.toml b/tests/modules/programs/yazi/flavor/flavor.toml new file mode 100644 index 000000000..35e1fe770 --- /dev/null +++ b/tests/modules/programs/yazi/flavor/flavor.toml @@ -0,0 +1,2 @@ +# This is a flavor. + diff --git a/tests/modules/programs/yazi/flavor/init.lua b/tests/modules/programs/yazi/flavor/init.lua deleted file mode 100644 index 8d06fa7a9..000000000 --- a/tests/modules/programs/yazi/flavor/init.lua +++ /dev/null @@ -1 +0,0 @@ --- This is a flavor. diff --git a/tests/modules/programs/yazi/flavor/preview.png b/tests/modules/programs/yazi/flavor/preview.png new file mode 100644 index 000000000..e69de29bb diff --git a/tests/modules/programs/yazi/flavor/tmtheme.xml b/tests/modules/programs/yazi/flavor/tmtheme.xml new file mode 100644 index 000000000..e69de29bb diff --git a/tests/modules/programs/yazi/settings.nix b/tests/modules/programs/yazi/settings.nix index 667038719..2694dadec 100644 --- a/tests/modules/programs/yazi/settings.nix +++ b/tests/modules/programs/yazi/settings.nix @@ -83,7 +83,7 @@ ## Produces warning #"flavor-with-suffix.yazi" = ./flavor; ## Fails assertion - #single-file-flavor = ./flavor/init.lua; + #single-file-flavor = ./flavor/flavor.toml; #empty-dir-flavor = ./empty; }; }; @@ -101,7 +101,7 @@ ${./init.lua} assertFileContent home-files/.config/yazi/plugins/testplugin.yazi/init.lua \ ${./plugin/init.lua} - assertFileContent home-files/.config/yazi/flavors/testflavor.yazi/init.lua \ - ${./flavor/init.lua} + assertFileContent home-files/.config/yazi/flavors/testflavor.yazi/flavor.toml \ + ${./flavor/flavor.toml} ''; }