1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01: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:
Chance Harrison 2023-10-02 08:24:37 +00:00 committed by Robert Helgesson
parent fcbc70a7ee
commit c36cb65c4a
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED

View file

@ -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";
};
'';
};