modules: add git module
This commit is contained in:
parent
2b92614d0e
commit
1d31c3d1d2
9 changed files with 131 additions and 87 deletions
14
flake.lock
14
flake.lock
|
@ -101,11 +101,11 @@
|
||||||
"gitsigns-nvim": {
|
"gitsigns-nvim": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1695571272,
|
"lastModified": 1713620636,
|
||||||
"narHash": "sha256-VJCtDnPSo5RgSC+czSIOvqGhpUT0dzvCzbLtup+Ctyo=",
|
"narHash": "sha256-UK3DyvrQ0kLm9wrMQ6tLDoDunoThbY/Yfjn+eCZpuMw=",
|
||||||
"owner": "lewis6991",
|
"owner": "lewis6991",
|
||||||
"repo": "gitsigns.nvim",
|
"repo": "gitsigns.nvim",
|
||||||
"rev": "bdeba1cec3faddd89146690c10b9a87949c0ee66",
|
"rev": "035da036e68e509ed158414416c827d022d914bd",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -213,11 +213,11 @@
|
||||||
},
|
},
|
||||||
"nix2lua": {
|
"nix2lua": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1713368896,
|
"lastModified": 1713641247,
|
||||||
"narHash": "sha256-ivvxVxSpuri8rYP3FVdcxSRrabejAz6iAQvXqdzEGLc=",
|
"narHash": "sha256-UDAxwO1vSkaPtmby04xjiHq5dxd03IBD3lkpFKYlV7Q=",
|
||||||
"ref": "refs/heads/main",
|
"ref": "refs/heads/main",
|
||||||
"rev": "98eaf7a9c2a7e608387debeca8f403885fbec0e4",
|
"rev": "8c4f3ca834ef7c07c9e3be3e006d7395c69a176c",
|
||||||
"revCount": 29,
|
"revCount": 36,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.pleshevski.ru/mynix/nix2lua"
|
"url": "https://git.pleshevski.ru/mynix/nix2lua"
|
||||||
},
|
},
|
||||||
|
|
50
flake.nix
50
flake.nix
|
@ -242,7 +242,7 @@
|
||||||
|
|
||||||
minimalNeovim = mkNeovim pkgs;
|
minimalNeovim = mkNeovim pkgs;
|
||||||
|
|
||||||
recommendedNeovim = minimalNeovim.override (prev: {
|
allNeovim = minimalNeovim.override (prev: {
|
||||||
modules = {
|
modules = {
|
||||||
catppuccin = { };
|
catppuccin = { };
|
||||||
nvim-tree-lua = {
|
nvim-tree-lua = {
|
||||||
|
@ -256,16 +256,17 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
nvim-treesitter = { };
|
nvim-treesitter = { };
|
||||||
|
git = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
plugins = with prev.nix2lua.lib; {
|
plugins = with prev.nix2lua.lib; {
|
||||||
lualine-nvim = pipe [
|
lualine-nvim = pipe1
|
||||||
(require "lualine")
|
(require "lualine")
|
||||||
(call "setup" [{
|
(call "setup" {
|
||||||
options.ignore_focus = [ "NvimTree" ];
|
options.ignore_focus = [ "NvimTree" ];
|
||||||
sections = {
|
sections = {
|
||||||
lualine_a = [
|
lualine_a = [
|
||||||
[ "filename" (namedField "path" 1) ]
|
[ "filename" (nf "path" 1) ]
|
||||||
];
|
];
|
||||||
lualine_b = [ "branch" "diff" "diagnostics" ];
|
lualine_b = [ "branch" "diff" "diagnostics" ];
|
||||||
lualine_c = [ "lsp_progress" ];
|
lualine_c = [ "lsp_progress" ];
|
||||||
|
@ -273,51 +274,14 @@
|
||||||
lualine_y = [ "progress" ];
|
lualine_y = [ "progress" ];
|
||||||
lualine_z = [ "location" "mode" ];
|
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 = {
|
packages = {
|
||||||
# default = recommendedNeovim;
|
|
||||||
# full = fullNeovim;
|
|
||||||
minimal = minimalNeovim;
|
minimal = minimalNeovim;
|
||||||
|
|
||||||
recommended = recommendedNeovim;
|
all = allNeovim;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
7
lib.nix
7
lib.nix
|
@ -1,7 +0,0 @@
|
||||||
{ lib, substituteAll, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
readSubFile = src: params: builtins.readFile
|
|
||||||
(substituteAll (params // { inherit src; }));
|
|
||||||
in
|
|
||||||
lib // { inherit readSubFile substituteAll; }
|
|
34
lib/vim.nix
Normal file
34
lib/vim.nix
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{ nix2lua }:
|
||||||
|
|
||||||
|
with nix2lua.lib;
|
||||||
|
{
|
||||||
|
fn.isdirectory = file: call1 "vim.fn.isdirectory" (var file);
|
||||||
|
|
||||||
|
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 ];
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ with nix2lua.lib;
|
||||||
{
|
{
|
||||||
catppuccin = [
|
catppuccin = [
|
||||||
(set "vim.g.catppuccin_flavour" flavour)
|
(set "vim.g.catppuccin_flavour" flavour)
|
||||||
(pipe [ (require "catppuccin") (call "setup" [ ]) ])
|
(pipe1 (require "catppuccin") (call0 "setup"))
|
||||||
(call "vim.cmd" [ "colorscheme catppuccin" ])
|
(call "vim.cmd" "colorscheme catppuccin")
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
53
modules/git.nix
Normal file
53
modules/git.nix
Normal 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";
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
{ nix2lua, ... }:
|
{ nix2lua, vim, ... }:
|
||||||
|
|
||||||
{ configs ? { }
|
{ configs ? { }
|
||||||
, keymaps ? [
|
, keymaps ? [
|
||||||
|
@ -8,17 +8,13 @@
|
||||||
}:
|
}:
|
||||||
|
|
||||||
with nix2lua.lib;
|
with nix2lua.lib;
|
||||||
let
|
let isEmptyVar = name: eq "" (var name); in
|
||||||
vimKeymapSet = { mode, bind, command }: call "vim.keymap.set" [ mode bind command ];
|
|
||||||
|
|
||||||
isEmptyVar = name: eq "" (var name);
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
nvim-web-devicons = true;
|
nvim-web-devicons = true;
|
||||||
|
|
||||||
nvim-tree-lua = (
|
nvim-tree-lua = (
|
||||||
[
|
[
|
||||||
(pipe [ (require "nvim-tree") (call "setup" [ configs ]) ])
|
(pipe1 (require "nvim-tree") (call "setup" configs))
|
||||||
|
|
||||||
(local (func "open_nvim_tree" [ "data" ] [
|
(local (func "open_nvim_tree" [ "data" ] [
|
||||||
# buffer is a [No Name]
|
# buffer is a [No Name]
|
||||||
|
@ -31,27 +27,24 @@ in
|
||||||
|
|
||||||
# buffer is a directory
|
# buffer is a directory
|
||||||
(local (set "isDirectory"
|
(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
|
return_void
|
||||||
])
|
)
|
||||||
|
|
||||||
# change to the directory
|
# change to the directory
|
||||||
(if' (var "isDirectory") [
|
(if' (var "isDirectory")
|
||||||
(call "vim.cmd.cd" [ (var "data.file") ])
|
(vim.cmd.cd "data.file")
|
||||||
])
|
)
|
||||||
|
|
||||||
# open the tree
|
# 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" [
|
(vim.api.nvim_create_autocmd [ "VimEnter" ] { callback = var "open_nvim_tree"; })
|
||||||
[ "VimEnter" ]
|
|
||||||
{ callback = var "open_nvim_tree"; }
|
|
||||||
])
|
|
||||||
]
|
]
|
||||||
++ (map vimKeymapSet keymaps)
|
++ (map vim.keymap.set keymaps)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{ nix2lua, pkgs }:
|
{ nix2lua, pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
defaultGrammars = g: [
|
defaultGrammars = g: [
|
||||||
|
@ -191,18 +191,18 @@ in
|
||||||
|
|
||||||
nvim-treesitter = [
|
nvim-treesitter = [
|
||||||
(local (set "parser_config"
|
(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" { })
|
(set "parser_config.d2" { })
|
||||||
|
|
||||||
(pipe [
|
(pipe1
|
||||||
(require "nvim-treesitter.configs")
|
(require "nvim-treesitter.configs")
|
||||||
(call "setup" [{
|
(call "setup" {
|
||||||
ensure_installed = { };
|
ensure_installed = { };
|
||||||
sync_install = false;
|
sync_install = false;
|
||||||
highlight.enable = true;
|
highlight.enable = true;
|
||||||
indent.enable = true;
|
indent.enable = true;
|
||||||
}])
|
})
|
||||||
])
|
)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
13
neovim.nix
13
neovim.nix
|
@ -31,7 +31,10 @@ let
|
||||||
plugins = mergeAttrs plugins';
|
plugins = mergeAttrs plugins';
|
||||||
modules = mergeAttrs modules';
|
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);
|
allModules = mergeAttrs (lib.mapAttrsToList importModule modules);
|
||||||
|
|
||||||
# Type: excludeOverride :: AttrSet -> AttrSet
|
# Type: excludeOverride :: AttrSet -> AttrSet
|
||||||
|
@ -56,7 +59,7 @@ let
|
||||||
"-- Plugin: ${builtins.trace "Plugin: ${name}" name}\n"
|
"-- Plugin: ${builtins.trace "Plugin: ${name}" name}\n"
|
||||||
+ (if lib.isString cfg then cfg
|
+ (if lib.isString cfg then cfg
|
||||||
else if lib.isAttrs cfg && cfg ? _type then toLua 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 if lib.isBool cfg then "" # Just skip lua config. Only enable the plugin.
|
||||||
else abort "[neovim] mkPluginLuaConfig: '${name}' has unsupported type '${builtins.typeOf cfg}'");
|
else abort "[neovim] mkPluginLuaConfig: '${name}' has unsupported type '${builtins.typeOf cfg}'");
|
||||||
pluginLuaConfigs = lib.mapAttrsToList mkPluginLuaConfig pluginsWithModules;
|
pluginLuaConfigs = lib.mapAttrsToList mkPluginLuaConfig pluginsWithModules;
|
||||||
|
@ -68,7 +71,11 @@ let
|
||||||
/*
|
/*
|
||||||
Type: mkLuaHeredoc :: string -> string
|
Type: mkLuaHeredoc :: string -> string
|
||||||
*/
|
*/
|
||||||
mkLuaHeredoc = content: lib.concatLines [ "lua << EOF" content "EOF" ];
|
mkLuaHeredoc = content: ''
|
||||||
|
lua << EOF
|
||||||
|
${content}
|
||||||
|
EOF
|
||||||
|
'';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Type: mkLuaRc :: [string] -> string
|
Type: mkLuaRc :: [string] -> string
|
||||||
|
|
Reference in a new issue