Compare commits

...

3 Commits

8 changed files with 148 additions and 144 deletions

View File

@ -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"
},

View File

@ -208,7 +208,7 @@
buildPlugin = name: vimUtils.buildVimPlugin {
name = name;
src = getAttr name inputs;
patches = lib.optional
patches = lib.optionals
(pathExists ./patches/${name})
(map
(patchName: ./patches/${name}/${patchName})
@ -243,32 +243,42 @@
minimalNeovim = mkNeovim pkgs;
recommendedNeovim = (minimalNeovim.override {
enableDevIcons = true;
enableTabby = false;
recommendedNeovim = minimalNeovim.override {
modules = {
nvim-tree-lua = {
configs = {
renderer = {
group_empty = true;
full_name = true;
};
plugins = with minimalNeovim.nix2lua; {
nvimTree.settings = {
renderer = {
group_empty = true;
full_name = true;
};
};
lualine.settings = {
options.ignore_focus = [ "NvimTree" ];
sections = {
lualine_a = [
[ "filename" (mkNamedField "path" 1) ]
];
lualine_b = [ "branch" "diff" "diagnostics" ];
lualine_c = [ "lsp_progress" ];
lualine_x = [ "filesize" "filetype" ];
lualine_y = [ "progress" ];
lualine_z = [ "location" "mode" ];
};
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" (namedField "path" 1) ]
];
lualine_b = [ "branch" "diff" "diagnostics" ];
lualine_c = [ "lsp_progress" ];
lualine_x = [ "filesize" "filetype" ];
lualine_y = [ "progress" ];
lualine_z = [ "location" "mode" ];
};
}])
];
};
};
fullNeovim = recommendedNeovim.override {
plugins = recommendedNeovim.plugins // (with minimalNeovim.nix2lua; {
@ -305,22 +315,16 @@
};
packages = {
default = recommendedNeovim;
recommended = recommendedNeovim;
full = fullNeovim;
# default = recommendedNeovim;
# full = fullNeovim;
minimal = minimalNeovim;
};
mkApp = drv: {
type = "app";
program = "${drv}/bin/nvim";
recommended = recommendedNeovim;
};
in
{
inherit packages;
apps = mapAttrs (name: mkApp) packages;
devShells.default = pkgs.mkShell {
packages = [
pkgs.stylua # lua formatter

60
lib.nix
View File

@ -1,65 +1,7 @@
{ lib, substituteAll, ... }:
let
inherit (builtins) length elemAt isList isString hasAttr getAttr;
###########################################################################
# Helpers
# Source: https://github.com/NixOS/nixpkgs/blob/d61bc96d16ca288c69b798b8e31eca64050098e3/lib/lists.nix
foldr = op: nul: list:
let
len = length list;
fold' = n:
if n == len
then nul
else op (elemAt list n) (fold' (n + 1));
in
fold' 0;
concatMap = op: list:
let
concat = (a: b: op a + b);
in
foldr concat "" list;
############################################################################
# Configs
optional = cond: val:
let
def =
if isList val then [ ]
else if isString val then ""
else null;
in
if cond then val else def;
getAttrOpt = a: s:
if hasAttr a s then getAttr a s else null;
#############################################################################
# Lua
mkLuaHeredoc = content: ''
lua << EOF
${content}
EOF
'';
mkLuaRc = contents: concatMap mkLuaHeredoc contents;
############################################################################
# Configs
readSubFile = src: params: builtins.readFile
(substituteAll (params // { inherit src; }));
in
{
inherit (lib) importJSON attrByPath;
inherit foldr concatMap;
inherit optional getAttrOpt;
inherit mkLuaHeredoc mkLuaRc;
inherit readSubFile substituteAll;
}
lib // { inherit readSubFile substituteAll; }

55
modules/nvim-tree-lua.nix Normal file
View 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)
);
}

View File

@ -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,40 +28,45 @@ let
in
let
plugins = mergeAttrs plugins';
inherit (builtins) catAttrs readFile;
myLib = 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 = myLib;
};
/*
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" ];
/*
Type: mkLuaRc :: [string] -> string
*/
mkLuaRc = list: lib.concatLines (map mkLuaHeredoc list);
in
(wrapNeovim neovim-unwrapped {
inherit viAlias;
@ -77,7 +77,7 @@ in
withRuby = false;
configure = {
customRC = extraConfig + myLib.mkLuaRc allConfigs;
customRC = extraConfig + mkLuaRc allLuaConfigs;
packages.myVimPackages = { start = allPlugins; };
};

View File

@ -18,14 +18,17 @@ let
max_lines = 100;
};
tabbymlSettings = lib.toLua (lib.attrByPath [ "tabbyml" "settings" ] tabbymlDefaultSettings plugins);
tabbymlLuaConfig = lib.optional tabbymlEnable
tabbymlLuaConfig = lib.optionalString tabbymlEnable
(lib.readSubFile ./cmp-tabby.lua { inherit tabbymlSettings; });
cmpSources = lib.toLua ([
{ name = "nvim_lsp"; }
{ name = "luasnip"; }
{ name = "orgmode"; }
] ++ lib.optional tabbymlEnable [{ name = "cmp_tabby"; }]);
cmpSources = lib.toLua (
[
{ name = "nvim_lsp"; }
{ name = "luasnip"; }
{ name = "orgmode"; }
]
++ lib.optional tabbymlEnable { name = "cmp_tabby"; }
);
cmpLuaConfig = lib.readSubFile ./nvim-cmp.lua { inherit cmpSources; };
lspconfigLuaConfig = lib.readSubFile ./lspconfig.lua
@ -37,7 +40,7 @@ let
nvim-cmp # Autocompletion
cmp-nvim-lsp # LSP source for nvim-cmp
cmp-luasnip # Snippets source for nvim-cmp
] ++ lib.optional tabbymlEnable [ cmp-tabby ];
] ++ lib.optional tabbymlEnable cmp-tabby;
lspConfigServers = lib.toLua (lib.attrByPath [ "lspConfig" "servers" ] [ ] plugins);
lspSagaSettings = lib.toLua (lib.attrByPath [ "lspSaga" "settings" ] { } plugins);

View File

@ -27,10 +27,10 @@ in
{
luaConfig = themeConfig
+ (readFile (lib.substituteAll { src = ./lualine.lua; inherit lualineSettings; }))
+ (lib.optional enableTabby (readFile ./tabby-nvim.lua));
+ (lib.optionalString enableTabby (readFile ./tabby-nvim.lua));
plugins = [ theme ]
++ lualinePlugins
++ (lib.optional enableDevIcons [ nvim-web-devicons ])
++ (lib.optional enableTabby [ tabby-nvim ]);
++ (lib.optional enableDevIcons nvim-web-devicons)
++ (lib.optional enableTabby tabby-nvim);
}

View File

@ -15,7 +15,7 @@ let
orgmodeEnable = lib.attrByPath [ "orgmode" "enable" ] enableOrgMode plugins;
orgmodeSettings = lib.toLua (lib.attrByPath [ "orgmode" "settings" ] { } plugins);
orgmodeLuaConfig = lib.optional orgmodeEnable
orgmodeLuaConfig = lib.optionalString orgmodeEnable
(lib.readSubFile ./nvim-orgmode.lua { inherit orgmodeSettings; });
colorizerFiletypes = lib.toLua (lib.attrByPath [ "colorizer" "filetypes" ] lib.LuaNil plugins);
@ -28,5 +28,5 @@ in
luaConfig = hopLuaConfig + orgmodeLuaConfig + colorizerLuaConfig;
plugins = [ hop-nvim nvim-colorizer ]
++ lib.optional orgmodeEnable [ nvim-orgmode org-bullets-nvim ];
++ lib.optionals orgmodeEnable [ nvim-orgmode org-bullets-nvim ];
}