mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-14 11:57:55 +00:00
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 changed files with 48 additions and 21 deletions
|
@ -1,8 +1,7 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
inherit (lib)
|
||||
concatStringsSep types mkIf mkOption mkEnableOption mkPackageOption
|
||||
literalExpression;
|
||||
types mkIf mkOption mkEnableOption mkPackageOption literalExpression;
|
||||
|
||||
cfg = config.programs.xplr;
|
||||
|
||||
|
@ -10,21 +9,39 @@ let
|
|||
version = '${cfg.package.version}'
|
||||
'';
|
||||
|
||||
# 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.
|
||||
pluginPath = if cfg.plugins != [ ] then
|
||||
(''
|
||||
package.path=
|
||||
'' + (concatStringsSep " ..\n"
|
||||
(map (p: ''"${p}/init.lua;${p}/?.lua;"'') cfg.plugins)) + ''
|
||||
..
|
||||
package.path
|
||||
'')
|
||||
# If `value` is a Nix store path, create the symlink `/nix/store/newhash/${name}/*`
|
||||
# to `/nix/store/oldhash/*` and returns `/nix/store/newhash`.
|
||||
wrapPlugin = name: value:
|
||||
if lib.isStorePath value then
|
||||
pkgs.symlinkJoin {
|
||||
name = name;
|
||||
paths = [ value ];
|
||||
postBuild = ''
|
||||
mkdir '${name}'
|
||||
mv $out/* '${name}/'
|
||||
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
|
||||
"\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;
|
||||
in {
|
||||
meta.maintainers = [ lib.maintainers.NotAShelf ];
|
||||
|
@ -35,15 +52,25 @@ in {
|
|||
package = mkPackageOption pkgs "xplr" { };
|
||||
|
||||
plugins = mkOption {
|
||||
type = with types; nullOr (listOf (either package str));
|
||||
default = [ ];
|
||||
defaultText = literalExpression "[]";
|
||||
type = with types; nullOr (attrsOf (either package str));
|
||||
default = { };
|
||||
defaultText = literalExpression "{ }";
|
||||
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
|
||||
by xplr. Paths will be relative to
|
||||
{file}`$XDG_CONFIG_HOME/xplr/init.lua` unless they are absolute.
|
||||
Must be a package or string representing the plugin directory's path.
|
||||
If the path string is not absolute, it will be relative to {file}`$XDG_CONFIG_HOME/xplr/init.lua`.
|
||||
'';
|
||||
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