From 720d97a404142730c928936dba2b268664293a3f Mon Sep 17 00:00:00 2001 From: Chance Harrison <7481945+ChanceHarrison@users.noreply.github.com> Date: Mon, 2 Oct 2023 08:24:37 +0000 Subject: [PATCH] xplr: support multiple plugins in cfg.plugins Fixes ##4520 Co-authored-by: Arijit Basu <11632726+sayanarijit@users.noreply.github.com> --- modules/programs/xplr.nix | 69 +++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/modules/programs/xplr.nix b/modules/programs/xplr.nix index 22aca027d..bd9222954 100644 --- a/modules/programs/xplr.nix +++ b/modules/programs/xplr.nix @@ -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] 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"; + }; ''; };