xplr: support multiple plugins in cfg.plugins
Fixes ##4520 Co-authored-by: Arijit Basu <11632726+sayanarijit@users.noreply.github.com>
This commit is contained in:
parent
fcbc70a7ee
commit
c36cb65c4a
|
@ -1,8 +1,7 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
concatStringsSep types mkIf mkOption mkEnableOption mkPackageOption
|
types mkIf mkOption mkEnableOption mkPackageOption literalExpression;
|
||||||
literalExpression;
|
|
||||||
|
|
||||||
cfg = config.programs.xplr;
|
cfg = config.programs.xplr;
|
||||||
|
|
||||||
|
@ -10,21 +9,39 @@ let
|
||||||
version = '${cfg.package.version}'
|
version = '${cfg.package.version}'
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# We provide a default version line within the configuration file, which is
|
# If `value` is a Nix store path, create the symlink `/nix/store/newhash/${name}/*`
|
||||||
# obtained from the package's attributes. Merge the initial configFile, a
|
# to `/nix/store/oldhash/*` and returns `/nix/store/newhash`.
|
||||||
# mapped list of plugins and then the user defined configuration to obtain the
|
wrapPlugin = name: value:
|
||||||
# final configuration.
|
if lib.isStorePath value then
|
||||||
pluginPath = if cfg.plugins != [ ] then
|
pkgs.symlinkJoin {
|
||||||
(''
|
name = name;
|
||||||
package.path=
|
paths = [ value ];
|
||||||
'' + (concatStringsSep " ..\n"
|
postBuild = ''
|
||||||
(map (p: ''"${p}/init.lua;${p}/?.lua;"'') cfg.plugins)) + ''
|
mkdir '${name}'
|
||||||
..
|
mv $out/* '${name}/'
|
||||||
package.path
|
mv '${name}' $out/
|
||||||
'')
|
'';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
builtins.dirOf value;
|
||||||
|
|
||||||
|
makePluginSearchPath = p: "${p}/?/init.lua;${p}/?.lua";
|
||||||
|
|
||||||
|
pluginPath = if cfg.plugins != { } then
|
||||||
|
let
|
||||||
|
wrappedPlugins = lib.mapAttrsToList wrapPlugin cfg.plugins;
|
||||||
|
searchPaths = map makePluginSearchPath wrappedPlugins;
|
||||||
|
pluginSearchPath = lib.concatStringsSep ";" searchPaths;
|
||||||
|
in (''
|
||||||
|
package.path = "${pluginSearchPath};" .. package.path
|
||||||
|
'')
|
||||||
else
|
else
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
|
# We provide a default version line within the configuration file, which is
|
||||||
|
# obtained from the package's attributes. Merge the initial configFile, a
|
||||||
|
# mapped list of plugins and then the user defined configuration to obtain
|
||||||
|
# the final configuration.
|
||||||
configFile = initialConfig + pluginPath + cfg.extraConfig;
|
configFile = initialConfig + pluginPath + cfg.extraConfig;
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [ lib.maintainers.NotAShelf ];
|
meta.maintainers = [ lib.maintainers.NotAShelf ];
|
||||||
|
@ -35,15 +52,25 @@ in {
|
||||||
package = mkPackageOption pkgs "xplr" { };
|
package = mkPackageOption pkgs "xplr" { };
|
||||||
|
|
||||||
plugins = mkOption {
|
plugins = mkOption {
|
||||||
type = with types; nullOr (listOf (either package str));
|
type = with types; nullOr (attrsOf (either package str));
|
||||||
default = [ ];
|
default = { };
|
||||||
defaultText = literalExpression "[]";
|
defaultText = literalExpression "{ }";
|
||||||
description = ''
|
description = ''
|
||||||
Plugins to be added to your configuration file.
|
An attribute set of plugin paths to be added to the [package.path]<https://www.lua.org/manual/5.4/manual.html#pdf-package.path> of the {file}`~/config/xplr/init.lua` configuration file.
|
||||||
|
|
||||||
Must be a package, an absolute plugin path, or string to be recognized
|
Must be a package or string representing the plugin directory's path.
|
||||||
by xplr. Paths will be relative to
|
If the path string is not absolute, it will be relative to {file}`$XDG_CONFIG_HOME/xplr/init.lua`.
|
||||||
{file}`$XDG_CONFIG_HOME/xplr/init.lua` unless they are absolute.
|
'';
|
||||||
|
example = literalExpression ''
|
||||||
|
{
|
||||||
|
wl-clipboard = fetchFromGitHub {
|
||||||
|
owner = "sayanarijit";
|
||||||
|
repo = "wl-clipboard.xplr";
|
||||||
|
rev = "a3ffc87460c5c7f560bffea689487ae14b36d9c3";
|
||||||
|
hash = "sha256-I4rh5Zks9hiXozBiPDuRdHwW5I7ppzEpQNtirY0Lcks=";
|
||||||
|
}
|
||||||
|
local-plugin = "/home/user/.config/plugins/local-plugin";
|
||||||
|
};
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue