1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-24 02:39:48 +01:00

yazi: Assert that plugins have valid structure

This commit is contained in:
lordkekz 2024-06-03 20:29:06 +02:00 committed by Robert Helgesson
parent 5ccc3d6739
commit 340b98c0ab
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED

View file

@ -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);
};
}