Compare commits

...

3 Commits

10 changed files with 168 additions and 91 deletions

View File

@ -101,11 +101,11 @@
"gitsigns-nvim": {
"flake": false,
"locked": {
"lastModified": 1695571272,
"narHash": "sha256-VJCtDnPSo5RgSC+czSIOvqGhpUT0dzvCzbLtup+Ctyo=",
"lastModified": 1713620636,
"narHash": "sha256-UK3DyvrQ0kLm9wrMQ6tLDoDunoThbY/Yfjn+eCZpuMw=",
"owner": "lewis6991",
"repo": "gitsigns.nvim",
"rev": "bdeba1cec3faddd89146690c10b9a87949c0ee66",
"rev": "035da036e68e509ed158414416c827d022d914bd",
"type": "github"
},
"original": {
@ -213,11 +213,11 @@
},
"nix2lua": {
"locked": {
"lastModified": 1713368896,
"narHash": "sha256-ivvxVxSpuri8rYP3FVdcxSRrabejAz6iAQvXqdzEGLc=",
"lastModified": 1713645801,
"narHash": "sha256-pev5YkdskHDS4OpGdYb5F/44hKrFmqzCwNGs0vSzqM8=",
"ref": "refs/heads/main",
"rev": "98eaf7a9c2a7e608387debeca8f403885fbec0e4",
"revCount": 29,
"rev": "3c08fa87d14704db1c1648b2486ed49e721dfe18",
"revCount": 37,
"type": "git",
"url": "https://git.pleshevski.ru/mynix/nix2lua"
},

View File

@ -242,7 +242,7 @@
minimalNeovim = mkNeovim pkgs;
recommendedNeovim = minimalNeovim.override (prev: {
allNeovim = minimalNeovim.override (prev: {
modules = {
catppuccin = { };
nvim-tree-lua = {
@ -250,22 +250,20 @@
group_empty = true;
full_name = true;
};
keymaps = [
{ mode = "n"; bind = "<leader>nt"; command = "<CMD>NvimTreeToggle<CR>"; }
{ mode = "n"; bind = "<leader>nf"; command = "<CMD>NvimTreeFindFile<CR>"; }
];
};
nvim-treesitter = { };
gitsigns-nvim = { };
neoformat = { };
};
plugins = with prev.nix2lua.lib; {
lualine-nvim = pipe [
lualine-nvim = pipe1
(require "lualine")
(call "setup" [{
(call "setup" {
options.ignore_focus = [ "NvimTree" ];
sections = {
lualine_a = [
[ "filename" (namedField "path" 1) ]
[ "filename" (nf "path" 1) ]
];
lualine_b = [ "branch" "diff" "diagnostics" ];
lualine_c = [ "lsp_progress" ];
@ -273,51 +271,14 @@
lualine_y = [ "progress" ];
lualine_z = [ "location" "mode" ];
};
}])
];
});
};
});
fullNeovim = recommendedNeovim.override {
plugins = recommendedNeovim.plugins // (with minimalNeovim.nix2lua; {
lspSaga.settings = {
border_style = "rounded";
symbol_in_winbar.enable = false;
code_action_lightbulb.enable = false;
code_action_keys = { quit = "<Esc>"; };
definition_action_keys = { quit = "<Esc>"; };
rename_action_quit = "<C-c>";
};
lspConfig = {
servers = {
nil_ls = { };
tsserver = { };
eslint = { };
denols = {
root_dir = mkLuaRaw "root_pattern(\"deno.json\", \"deno.jsonc\")";
};
rust_analyzer = {
settings.rust-analyzer = {
"server.path" = "rust-analyzer";
"updates.prompt" = false;
"updates.checkOnStartup" = false;
"checkOnSave.enable" = true;
"checkOnSave.command" = "clippy";
"cargo.autoreload" = true;
};
};
};
};
tabbyml.enable = true;
});
};
packages = {
# default = recommendedNeovim;
# full = fullNeovim;
minimal = minimalNeovim;
recommended = recommendedNeovim;
all = allNeovim;
};
in
{

View File

@ -1,7 +0,0 @@
{ lib, substituteAll, ... }:
let
readSubFile = src: params: builtins.readFile
(substituteAll (params // { inherit src; }));
in
lib // { inherit readSubFile substituteAll; }

36
lib/vim.nix Normal file
View File

@ -0,0 +1,36 @@
{ nix2lua }:
with nix2lua.lib;
{
g = varName: expr: set "vim.g.${varName}" expr;
fn.isdirectory = file: call1 "vim.fn.isdirectory" (var file);
cmd' = expr: call1 "vim.cmd" expr;
cmd.cd = file: call1 "vim.cmd.cd" (var file);
keymap.set = { mode, bind, command, opts ? { } }:
call "vim.keymap.set" [ mode bind command opts ];
/*
Parameters:
- {event} (string|array) Event(s) that will trigger the handler (callback or command).
- {opts} Options dict:
- group (string|integer) optional: autocommand group name or id to match against.
- pattern (string|array) optional: pattern(s) to match literally autocmd-pattern.
- buffer (integer) optional: buffer number for buffer-local autocommands autocmd-buflocal. Cannot be used with {pattern}.
- desc (string) optional: description (for documentation and troubleshooting).
- callback (function|string) optional: Lua function (or Vimscript function name, if string) called when the event(s) is triggered. Lua callback can return a truthy value (not false or nil) to delete the autocommand. Receives a table argument with these keys:
- id: (number) autocommand id
- event: (string) name of the triggered event autocmd-events
- group: (number|nil) autocommand group id, if any
- match: (string) expanded value of <amatch>
- buf: (number) expanded value of <abuf>
- file: (string) expanded value of <afile>
- data: (any) arbitrary data passed from nvim_exec_autocmds()
- command (string) optional: Vim command to execute on event. Cannot be used with {callback}
- once (boolean) optional: defaults to false. Run the autocommand only once autocmd-once.
- nested (boolean) optional: defaults to false. Run nested autocommands autocmd-nested.
*/
api.nvim_create_autocmd = event: opts:
call "vim.api.nvim_create_autocmd" [ event opts ];
}

View File

@ -7,7 +7,7 @@ with nix2lua.lib;
{
catppuccin = [
(set "vim.g.catppuccin_flavour" flavour)
(pipe [ (require "catppuccin") (call "setup" [ ]) ])
(call "vim.cmd" [ "colorscheme catppuccin" ])
(pipe1 (require "catppuccin") (call0 "setup"))
(call "vim.cmd" "colorscheme catppuccin")
];
}

53
modules/gitsigns-nvim.nix Normal file
View File

@ -0,0 +1,53 @@
{ nix2lua, vim, lib, ... }:
with nix2lua.lib;
{ configs ? { }
, keymaps ? [
{ mode = "n"; bind = "]h"; command = raw "next_hunk"; }
{ mode = "n"; bind = "[h"; command = raw "prev_hunk"; }
{ mode = "n"; bind = "<leader>gs"; command = raw "gs.stage_hunk"; }
{ mode = "n"; bind = "<leader>gr"; command = raw "gs.reset_hunk"; }
{ mode = "n"; bind = "<leader>gu"; command = raw "gs.undo_stage_hunk"; }
{ mode = "n"; bind = "<leader>gp"; command = raw "gs.preview_hunk"; }
{ mode = "n"; bind = "<leader>gb"; command = lambda0 (call "gs.blame_line" { full = true; }); }
{ mode = "n"; bind = "<leader>gd"; command = raw "gs.diffthis"; }
{ mode = "n"; bind = "<leader>gD"; command = lambda0 (call "gs.diffthis" "~"); }
{ mode = "n"; bind = "<leader>gtb"; command = raw "gs.toggle_current_line_blame"; }
{ mode = "n"; bind = "<leader>gtd"; command = raw "gs.toggle_deleted"; }
]
}:
let
bufferedKeymaps = map (args: lib.recursiveUpdate args { opts.buffer = var "bufnr"; }) keymaps;
in
{
gitsigns-nvim = [
(local (func "on_attach" [ "bufnr" ] (
[
(local (set "gs" (var "package.loaded.gitsigns")))
(local (func0 "next_hunk"
(ifelse (var "vim.wo.diff")
(call1 "vim.cmd.normal" [ "]h" (nf "bang" true) ])
(call1 "gs.nav_hunk" "next")
)
))
(local (func0 "prev_hunk"
(ifelse (var "vim.wo.diff")
(call1 "vim.cmd.normal" [ "[h" (nf "bang" true) ])
(call1 "gs.nav_hunk" "prev"))
))
]
++ map vim.keymap.set bufferedKeymaps
)))
(pipe1
(require "gitsigns")
(call "setup" (configs // {
on_attach = var "on_attach";
}))
)
];
}

34
modules/neoformat.nix Normal file
View File

@ -0,0 +1,34 @@
{ vim, ... }:
{ configs ? {
neoformat_enabled_markdown = [ "denofmt" ];
neoformat_rust_rustfmt = {
exe = "rustfmt";
args = [ "--edition 2021" ];
stdin = 1;
};
}
}:
let inherit (builtins) concatLists attrValues mapAttrs; in
let
baseConfigs = {
neoformat_try_node_exe = 1;
neoformat_only_msg_on_error = 1;
};
in
{
neoformat = concatLists [
(attrValues (mapAttrs vim.g (baseConfigs // configs)))
[
(vim.cmd' ''
aug fmt
au!
au BufWritePre * try | undojoin | Neoformat | catch /E790/ | Neoformat | endtry
aug END
'')
]
];
}

View File

@ -1,4 +1,4 @@
{ nix2lua, ... }:
{ nix2lua, vim, ... }:
{ configs ? { }
, keymaps ? [
@ -8,17 +8,13 @@
}:
with nix2lua.lib;
let
vimKeymapSet = { mode, bind, command }: call "vim.keymap.set" [ mode bind command ];
isEmptyVar = name: eq "" (var name);
in
let isEmptyVar = name: eq "" (var name); in
{
nvim-web-devicons = true;
nvim-tree-lua = (
[
(pipe [ (require "nvim-tree") (call "setup" [ configs ]) ])
(pipe1 (require "nvim-tree") (call "setup" configs))
(local (func "open_nvim_tree" [ "data" ] [
# buffer is a [No Name]
@ -31,27 +27,24 @@ in
# buffer is a directory
(local (set "isDirectory"
(eq 1 (var "vim.fn.isdirectory(data.file)"))
(eq 1 (vim.fn.isdirectory "data.file"))
))
(if' (not (and (var "isNoNameBuffer") (var "isDirectory"))) [
(if' (not (and (var "isNoNameBuffer") (var "isDirectory")))
return_void
])
)
# change to the directory
(if' (var "isDirectory") [
(call "vim.cmd.cd" [ (var "data.file") ])
])
(if' (var "isDirectory")
(vim.cmd.cd "data.file")
)
# open the tree
(pipe [ (require "nvim-tree.api") (call "tree.open" [ ]) ])
(pipe1 (require "nvim-tree.api") (call0 "tree.open"))
]))
(call "vim.api.nvim_create_autocmd" [
[ "VimEnter" ]
{ callback = var "open_nvim_tree"; }
])
(vim.api.nvim_create_autocmd [ "VimEnter" ] { callback = var "open_nvim_tree"; })
]
++ (map vimKeymapSet keymaps)
++ (map vim.keymap.set keymaps)
);
}

View File

@ -1,4 +1,4 @@
{ nix2lua, pkgs }:
{ nix2lua, pkgs, ... }:
let
defaultGrammars = g: [
@ -191,18 +191,18 @@ in
nvim-treesitter = [
(local (set "parser_config"
(pipe [ (require "nvim-treesitter.parsers") (call "get_parser_configs" [ ]) ])
(pipe1 (require "nvim-treesitter.parsers") (call0 "get_parser_configs"))
))
(set "parser_config.d2" { })
(pipe [
(pipe1
(require "nvim-treesitter.configs")
(call "setup" [{
(call "setup" {
ensure_installed = { };
sync_install = false;
highlight.enable = true;
indent.enable = true;
}])
])
})
)
];
}

View File

@ -31,7 +31,10 @@ let
plugins = mergeAttrs plugins';
modules = mergeAttrs modules';
importModule = moduleName: import (./modules + "/${moduleName}.nix") { inherit nix2lua pkgs; };
vim = import ./lib/vim.nix { inherit nix2lua; };
importModule = moduleName:
import (./modules + "/${moduleName}.nix") { inherit nix2lua pkgs vim lib; };
allModules = mergeAttrs (lib.mapAttrsToList importModule modules);
# Type: excludeOverride :: AttrSet -> AttrSet
@ -56,7 +59,7 @@ let
"-- Plugin: ${builtins.trace "Plugin: ${name}" name}\n"
+ (if lib.isString cfg then cfg
else if lib.isAttrs cfg && cfg ? _type then toLua cfg
else if lib.isList cfg then toLua (concatLines cfg)
else if lib.isList cfg then toLua (spaceBetween cfg)
else if lib.isBool cfg then "" # Just skip lua config. Only enable the plugin.
else abort "[neovim] mkPluginLuaConfig: '${name}' has unsupported type '${builtins.typeOf cfg}'");
pluginLuaConfigs = lib.mapAttrsToList mkPluginLuaConfig pluginsWithModules;
@ -68,7 +71,11 @@ let
/*
Type: mkLuaHeredoc :: string -> string
*/
mkLuaHeredoc = content: lib.concatLines [ "lua << EOF" content "EOF" ];
mkLuaHeredoc = content: ''
lua << EOF
${content}
EOF
'';
/*
Type: mkLuaRc :: [string] -> string