add nvim-tree-lua module
This commit is contained in:
parent
d3e0b8c0d9
commit
3eb6c9b8d8
4 changed files with 132 additions and 74 deletions
|
@ -197,11 +197,11 @@
|
|||
},
|
||||
"nix2lua": {
|
||||
"locked": {
|
||||
"lastModified": 1709128456,
|
||||
"narHash": "sha256-tRduS+XFI6VceWPQzjkuvlyn/Oe5NsQUS/wyEC69dvk=",
|
||||
"lastModified": 1713368896,
|
||||
"narHash": "sha256-ivvxVxSpuri8rYP3FVdcxSRrabejAz6iAQvXqdzEGLc=",
|
||||
"ref": "refs/heads/main",
|
||||
"rev": "f152767145e61fea96eddb1b550ab3f25701e0ad",
|
||||
"revCount": 18,
|
||||
"rev": "98eaf7a9c2a7e608387debeca8f403885fbec0e4",
|
||||
"revCount": 29,
|
||||
"type": "git",
|
||||
"url": "https://git.pleshevski.ru/mynix/nix2lua"
|
||||
},
|
||||
|
|
35
flake.nix
35
flake.nix
|
@ -243,22 +243,31 @@
|
|||
|
||||
minimalNeovim = mkNeovim pkgs;
|
||||
|
||||
recommendedNeovim = (minimalNeovim.override {
|
||||
enableDevIcons = true;
|
||||
enableTabby = false;
|
||||
|
||||
plugins = with minimalNeovim.nix2lua; {
|
||||
nvimTree.settings = {
|
||||
recommendedNeovim = minimalNeovim.override {
|
||||
modules = {
|
||||
nvim-tree-lua = {
|
||||
configs = {
|
||||
renderer = {
|
||||
group_empty = true;
|
||||
full_name = true;
|
||||
};
|
||||
|
||||
};
|
||||
lualine.settings = {
|
||||
keymaps = [
|
||||
{ mode = "n"; bind = "<leader>nt"; command = "<CMD>NvimTreeToggle<CR>"; }
|
||||
{ mode = "n"; bind = "<leader>nf"; command = "<CMD>NvimTreeFindFile<CR>"; }
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
plugins = with minimalNeovim.nix2lua; {
|
||||
lualine-nvim = pipe [
|
||||
(require "lualine")
|
||||
(call "setup" [{
|
||||
options.ignore_focus = [ "NvimTree" ];
|
||||
sections = {
|
||||
lualine_a = [
|
||||
[ "filename" (mkNamedField "path" 1) ]
|
||||
[ "filename" (namedField "path" 1) ]
|
||||
];
|
||||
lualine_b = [ "branch" "diff" "diagnostics" ];
|
||||
lualine_c = [ "lsp_progress" ];
|
||||
|
@ -266,9 +275,10 @@
|
|||
lualine_y = [ "progress" ];
|
||||
lualine_z = [ "location" "mode" ];
|
||||
};
|
||||
}])
|
||||
];
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
fullNeovim = recommendedNeovim.override {
|
||||
plugins = recommendedNeovim.plugins // (with minimalNeovim.nix2lua; {
|
||||
|
@ -305,10 +315,11 @@
|
|||
};
|
||||
|
||||
packages = {
|
||||
default = recommendedNeovim;
|
||||
recommended = recommendedNeovim;
|
||||
full = fullNeovim;
|
||||
# default = recommendedNeovim;
|
||||
# full = fullNeovim;
|
||||
minimal = minimalNeovim;
|
||||
|
||||
recommended = recommendedNeovim;
|
||||
};
|
||||
in
|
||||
{
|
||||
|
|
55
modules/nvim-tree-lua.nix
Normal file
55
modules/nvim-tree-lua.nix
Normal file
|
@ -0,0 +1,55 @@
|
|||
{ nix2lua }:
|
||||
|
||||
{ configs ? { }
|
||||
, keymaps ? [
|
||||
{ mode = "n"; bind = "<leader>nt"; command = "<CMD>NvimTreeToggle<CR>"; }
|
||||
{ mode = "n"; bind = "<leader>nf"; command = "<CMD>NvimTreeFindFile<CR>"; }
|
||||
]
|
||||
}:
|
||||
|
||||
with nix2lua.lib;
|
||||
let
|
||||
vimKeymapSet = { mode, bind, command }: call "vim.keymap.set" [ mode bind command ];
|
||||
|
||||
isEmptyVar = name: eq "" (var name);
|
||||
in
|
||||
{
|
||||
nvim-tree-lua = (
|
||||
[
|
||||
(pipe [ (require "nvim-tree") (call "setup" [ configs ]) ])
|
||||
|
||||
(local (func "open_nvim_tree" [ "data" ] [
|
||||
# buffer is a [No Name]
|
||||
(local (set "isNoNameBuffer"
|
||||
(and
|
||||
(isEmptyVar "data.file")
|
||||
(isEmptyVar "vim.bo[data.buf].buftype")
|
||||
)
|
||||
))
|
||||
|
||||
# buffer is a directory
|
||||
(local (set "isDirectory"
|
||||
(eq 1 (var "vim.fn.isdirectory(data.file)"))
|
||||
))
|
||||
|
||||
(if' (not (and (var "isNoNameBuffer") (var "isDirectory"))) [
|
||||
return_void
|
||||
])
|
||||
|
||||
# change to the directory
|
||||
(if' (var "isDirectory") [
|
||||
(call "vim.cmd.cd" [ (var "data.file") ])
|
||||
])
|
||||
|
||||
# open the tree
|
||||
(pipe [ (require "nvim-tree.api") (call "tree.open" [ ]) ])
|
||||
]))
|
||||
|
||||
(call "vim.api.nvim_create_autocmd" [
|
||||
[ "VimEnter" ]
|
||||
{ callback = var "open_nvim_tree"; }
|
||||
])
|
||||
]
|
||||
++ (map vimKeymapSet keymaps)
|
||||
);
|
||||
}
|
82
neovim.nix
82
neovim.nix
|
@ -1,24 +1,19 @@
|
|||
{ enableDevIcons ? false
|
||||
, enableTabby ? false
|
||||
, enableOrgMode ? false
|
||||
, viAlias ? false
|
||||
{ viAlias ? false
|
||||
, vimAlias ? false
|
||||
, extraConfig ? ""
|
||||
, extraLuaConfig ? ""
|
||||
, extraPlugins ? [ ]
|
||||
, theme ? { }
|
||||
, plugins ? { }
|
||||
, wrapNeovim
|
||||
, neovim-unwrapped
|
||||
, tree-sitter
|
||||
, neovimPlugins
|
||||
, lib
|
||||
, nix2lua
|
||||
, substituteAll
|
||||
, callPackage
|
||||
, plugins ? { }
|
||||
, modules ? { }
|
||||
, ...
|
||||
}:
|
||||
|
||||
|
||||
let
|
||||
plugins' = plugins;
|
||||
|
||||
|
@ -33,48 +28,45 @@ let
|
|||
in
|
||||
let
|
||||
plugins = mergeAttrs plugins';
|
||||
inherit (builtins) catAttrs readFile;
|
||||
|
||||
extLib = import ./lib.nix { inherit lib substituteAll; } // {
|
||||
inherit (nix2lua.lib) toLua LuaNil;
|
||||
};
|
||||
importModule = moduleName: import (./modules + "/${moduleName}.nix") { inherit nix2lua; };
|
||||
|
||||
allModules = mergeAttrs (lib.mapAttrsToList importModule modules);
|
||||
|
||||
pluginsWithModules = mergeAttrs [ allModules plugins ];
|
||||
|
||||
|
||||
pluginParams = neovimPlugins // {
|
||||
inherit tree-sitter plugins enableDevIcons enableTabby enableOrgMode;
|
||||
themeCfg = theme;
|
||||
lib = extLib;
|
||||
};
|
||||
/*
|
||||
Type: getPluginByName :: string -> derivation
|
||||
*/
|
||||
getPluginByName = lib.flip lib.getAttr neovimPlugins;
|
||||
allPlugins = map getPluginByName (lib.attrNames pluginsWithModules);
|
||||
|
||||
callPlugin = plugin: callPackage plugin pluginParams;
|
||||
callPlugins = list: map callPlugin list;
|
||||
/*
|
||||
Type: mkPluginLuaConfig :: string -> a -> string
|
||||
*/
|
||||
mkPluginLuaConfig = name: cfg:
|
||||
with nix2lua.lib;
|
||||
"-- Plugin: ${builtins.trace "Plugin: ${name}" name}\n"
|
||||
+ (if lib.isString cfg then cfg
|
||||
else if lib.isAttrs cfg then toLua cfg
|
||||
else if lib.isList cfg then toLua (concatLines cfg)
|
||||
else abort "[neovim] mkPluginLuaConfig: unsupported type");
|
||||
pluginLuaConfigs = lib.mapAttrsToList mkPluginLuaConfig pluginsWithModules;
|
||||
|
||||
pluginsSettings = callPlugins [
|
||||
./plugins/config
|
||||
./plugins/syntax
|
||||
./plugins/git
|
||||
./plugins/explorer
|
||||
./plugins/theme
|
||||
./plugins/lsp
|
||||
./plugins/formatter
|
||||
./plugins/ux
|
||||
];
|
||||
basicLuaConfigs = map builtins.readFile [ ./config/basic.lua ];
|
||||
|
||||
basePlugins = [ neovimPlugins.plenary-nvim ];
|
||||
customPlugins = catAttrs "plugins" pluginsSettings;
|
||||
allPlugins = basePlugins ++ customPlugins ++ extraPlugins;
|
||||
allLuaConfigs = basicLuaConfigs ++ pluginLuaConfigs;
|
||||
|
||||
basicConfigs = map readFile [ ./config/basic.lua ];
|
||||
pluginConfigs = catAttrs "luaConfig" pluginsSettings;
|
||||
allConfigs = basicConfigs ++ pluginConfigs ++ [ extraLuaConfig ];
|
||||
/*
|
||||
Type: mkLuaHeredoc :: string -> string
|
||||
*/
|
||||
mkLuaHeredoc = content: lib.concatLines [ "lua << EOF" content "EOF" ];
|
||||
|
||||
mkLuaHeredoc = content: ''
|
||||
lua << EOF
|
||||
${content}
|
||||
EOF
|
||||
'';
|
||||
|
||||
mkLuaRc = lib.concatMapStrings mkLuaHeredoc;
|
||||
/*
|
||||
Type: mkLuaRc :: [string] -> string
|
||||
*/
|
||||
mkLuaRc = list: lib.concatLines (map mkLuaHeredoc list);
|
||||
in
|
||||
(wrapNeovim neovim-unwrapped {
|
||||
inherit viAlias;
|
||||
|
@ -85,13 +77,13 @@ in
|
|||
withRuby = false;
|
||||
|
||||
configure = {
|
||||
customRC = extraConfig + mkLuaRc allConfigs;
|
||||
customRC = extraConfig + mkLuaRc allLuaConfigs;
|
||||
|
||||
packages.myVimPackages = { start = allPlugins; };
|
||||
};
|
||||
}).overrideAttrs (oldAttrs: {
|
||||
passthru = oldAttrs.passthru // {
|
||||
nix2lua = nix2lua.lib;
|
||||
inherit plugins allConfigs;
|
||||
inherit plugins;
|
||||
};
|
||||
})
|
||||
|
|
Reference in a new issue