2023-07-13 21:34:47 +02:00
{ config , lib , pkgs , . . . }:
let
inherit ( lib )
2023-10-02 10:24:37 +02:00
types mkIf mkOption mkEnableOption mkPackageOption literalExpression ;
2023-07-13 21:34:47 +02:00
cfg = config . programs . xplr ;
initialConfig = ''
version = ' $ { cfg . package . version } '
'' ;
2023-10-02 10:24:37 +02:00
# 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 /* ' $ { n a m e } / '
mv ' $ { name } ' $ out /
'' ;
}
else
builtins . dirOf value ;
makePluginSearchPath = p : " ${ p } / ? / i n i t . l u a ; ${ p } / ? . l u a " ;
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
'' )
2023-07-13 21:34:47 +02:00
else
" \n " ;
2023-10-02 10:24:37 +02:00
# 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.
2023-07-13 21:34:47 +02:00
configFile = initialConfig + pluginPath + cfg . extraConfig ;
in {
meta . maintainers = [ lib . maintainers . NotAShelf ] ;
options . programs . xplr = {
enable = mkEnableOption " x p l r , t e r m i n a l U I b a s e d f i l e e x p l o r e r " ;
package = mkPackageOption pkgs " x p l r " { } ;
plugins = mkOption {
2023-10-02 10:24:37 +02:00
type = with types ; nullOr ( attrsOf ( either package str ) ) ;
default = { } ;
defaultText = literalExpression " { } " ;
2023-07-13 21:34:47 +02:00
description = ''
2023-10-02 10:24:37 +02:00
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.
2023-07-13 21:34:47 +02:00
2023-10-02 10:24:37 +02:00
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 = " s a y a n a r i j i t " ;
repo = " w l - c l i p b o a r d . x p l r " ;
rev = " a 3 f f c 8 7 4 6 0 c 5 c 7 f 5 6 0 b f f e a 6 8 9 4 8 7 a e 1 4 b 3 6 d 9 c 3 " ;
hash = " s h a 2 5 6 - I 4 r h 5 Z k s 9 h i X o z B i P D u R d H w W 5 I 7 p p z E p Q N t i r Y 0 L c k s = " ;
}
local-plugin = " / h o m e / u s e r / . c o n f i g / p l u g i n s / l o c a l - p l u g i n " ;
} ;
2023-07-13 21:34:47 +02:00
'' ;
} ;
extraConfig = mkOption {
type = types . lines ;
default = " " ;
example = literalExpression ''
require ( " w l - c l i p b o a r d " ) . setup {
copy_command = " w l - c o p y - t t e x t / u r i - l i s t " ,
paste_command = " w l - p a s t e " ,
keep_selection = true ,
}
'' ;
description = ''
Extra xplr configuration .
'' ;
} ;
} ;
config = mkIf cfg . enable {
home . packages = [ cfg . package ] ;
xdg . configFile . " x p l r / i n i t . l u a " . source =
pkgs . writeText " i n i t . l u a " configFile ;
} ;
}