integrate with nix2lua

This commit is contained in:
Dmitriy Pleshevskiy 2022-11-19 00:56:53 +03:00
parent 42e6ef422f
commit ea2231f615
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
13 changed files with 178 additions and 76 deletions

View file

@ -6,19 +6,23 @@
, vimAlias ? false , vimAlias ? false
, grammarFileTypes ? [ "nix" ] , grammarFileTypes ? [ "nix" ]
, theme ? { } , theme ? { }
, plugins ? { }
, wrapNeovim , wrapNeovim
, neovim-unwrapped , neovim-unwrapped
, tree-sitter , tree-sitter
, neovimPlugins , neovimPlugins
, lib , lib
, toLua
, substituteAll
, ... , ...
}: }:
let let
inherit (builtins) catAttrs isFunction readFile; inherit (builtins) catAttrs isFunction readFile;
myLib = import ./lib.nix { inherit lib; }; myLib = import ./lib.nix { inherit lib; } // { inherit substituteAll toLua; };
pluginParams = neovimPlugins // { pluginParams = neovimPlugins // {
inherit plugins;
inherit tree-sitter grammarFileTypes; inherit tree-sitter grammarFileTypes;
inherit enableDevIcons enableTabby enableOrgMode; inherit enableDevIcons enableTabby enableOrgMode;
themeCfg = theme; themeCfg = theme;
@ -29,7 +33,7 @@ let
if isFunction op then op pluginParams else import op pluginParams; if isFunction op then op pluginParams else import op pluginParams;
callPlugins = list: map callPlugin list; callPlugins = list: map callPlugin list;
plugins = callPlugins [ pluginsSettings = callPlugins [
./plugins/config ./plugins/config
./plugins/syntax ./plugins/syntax
./plugins/git ./plugins/git
@ -41,11 +45,11 @@ let
]; ];
basePlugins = [ neovimPlugins.plenary-nvim ]; basePlugins = [ neovimPlugins.plenary-nvim ];
customPlugins = catAttrs "plugins" plugins; customPlugins = catAttrs "plugins" pluginsSettings;
allPlugins = basePlugins ++ customPlugins; allPlugins = basePlugins ++ customPlugins;
basicConfigs = map readFile [ ./config/basic.lua ]; basicConfigs = map readFile [ ./config/basic.lua ];
pluginConfigs = catAttrs "luaConfig" plugins; pluginConfigs = catAttrs "luaConfig" pluginsSettings;
allConfigs = basicConfigs ++ pluginConfigs; allConfigs = basicConfigs ++ pluginConfigs;
in in
wrapNeovim neovim-unwrapped { wrapNeovim neovim-unwrapped {

View file

@ -51,6 +51,36 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitsigns-nvim": { "gitsigns-nvim": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -170,7 +200,42 @@
"type": "github" "type": "github"
} }
}, },
"nix2lua": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1668806730,
"narHash": "sha256-CfRF/O5ObRBGCQkrUBsNWzKH2OjLNtOOuVk8H2dMoxQ=",
"ref": "refs/heads/main",
"rev": "9666618527a63e79ccc1855beeab285cd8480727",
"revCount": 6,
"type": "git",
"url": "https://git.pleshevski.ru/mynix/nix2lua"
},
"original": {
"type": "git",
"url": "https://git.pleshevski.ru/mynix/nix2lua"
}
},
"nixpkgs": { "nixpkgs": {
"locked": {
"lastModified": 1668650906,
"narHash": "sha256-JuiYfDO23O8oxUUOmhQflmOoJovyC5G4RjcYQMQjrRE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3a86856a13c88c8c64ea32082a851fefc79aa700",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1667969101, "lastModified": 1667969101,
"narHash": "sha256-GL53T705HO7Q/KVfbb5STx8AxFs8YgaGY8pvAZC+O7U=", "narHash": "sha256-GL53T705HO7Q/KVfbb5STx8AxFs8YgaGY8pvAZC+O7U=",
@ -342,6 +407,7 @@
"cmp-luasnip": "cmp-luasnip", "cmp-luasnip": "cmp-luasnip",
"cmp-nvim-lsp": "cmp-nvim-lsp", "cmp-nvim-lsp": "cmp-nvim-lsp",
"editorconfig-nvim": "editorconfig-nvim", "editorconfig-nvim": "editorconfig-nvim",
"flake-utils": "flake-utils",
"gitsigns-nvim": "gitsigns-nvim", "gitsigns-nvim": "gitsigns-nvim",
"hop-nvim": "hop-nvim", "hop-nvim": "hop-nvim",
"lspsaga-nvim": "lspsaga-nvim", "lspsaga-nvim": "lspsaga-nvim",
@ -349,7 +415,8 @@
"lualine-nvim": "lualine-nvim", "lualine-nvim": "lualine-nvim",
"luasnip": "luasnip", "luasnip": "luasnip",
"neoformat": "neoformat", "neoformat": "neoformat",
"nixpkgs": "nixpkgs", "nix2lua": "nix2lua",
"nixpkgs": "nixpkgs_2",
"nlsp-settings-nvim": "nlsp-settings-nvim", "nlsp-settings-nvim": "nlsp-settings-nvim",
"nvim-cmp": "nvim-cmp", "nvim-cmp": "nvim-cmp",
"nvim-lspconfig": "nvim-lspconfig", "nvim-lspconfig": "nvim-lspconfig",
@ -362,8 +429,7 @@
"tabby-nvim": "tabby-nvim", "tabby-nvim": "tabby-nvim",
"telescope-live-grep-args-nvim": "telescope-live-grep-args-nvim", "telescope-live-grep-args-nvim": "telescope-live-grep-args-nvim",
"telescope-nvim": "telescope-nvim", "telescope-nvim": "telescope-nvim",
"theme": "theme", "theme": "theme"
"utils": "utils"
} }
}, },
"tabby-nvim": { "tabby-nvim": {
@ -433,21 +499,6 @@
"rev": "9ac18414f0446478024b19018d73b7ea14f6fc96", "rev": "9ac18414f0446478024b19018d73b7ea14f6fc96",
"type": "github" "type": "github"
} }
},
"utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View file

@ -1,7 +1,9 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
nix2lua.url = "git+https://git.pleshevski.ru/mynix/nix2lua";
# Plenary (required by crates-nvim) # Plenary (required by crates-nvim)
plenary-nvim = { plenary-nvim = {
@ -158,7 +160,7 @@
}; };
}; };
outputs = inputs @ { self, nixpkgs, utils, ... }: outputs = inputs @ { self, nixpkgs, flake-utils, nix2lua, ... }:
let let
inputPlugins = [ inputPlugins = [
"plenary-nvim" "plenary-nvim"
@ -219,21 +221,78 @@
{ {
overlays = { overlays = {
default = final: prev: { default = final: prev: {
myneovim = prev.callPackage self (mkNvimPlugins prev); myneovim = prev.callPackage self (mkNvimPlugins prev // nix2lua.lib);
}; };
}; };
} // } //
utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
neovim = pkgs.callPackage self (mkNvimPlugins pkgs); neovim = pkgs.callPackage self (mkNvimPlugins pkgs // nix2lua.lib);
testNeovim = (neovim.override { testNeovim = (neovim.override {
enableDevIcons = true; enableDevIcons = true;
enableTabby = true; enableTabby = true;
enableOrgMode = true; enableOrgMode = true;
grammarFileTypes = [ "nix" "lua" "org" ]; grammarFileTypes = [ "nix" "lua" "org" ];
plugins = with nix2lua.lib; {
nvimTree.settings = {
open_on_setup = true;
renderer = {
group_empty = true;
full_name = true;
};
};
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 = {
nix = { };
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;
};
};
};
};
lualine.settings = {
options.ignore_focus = [ "NvimTree" ];
sections = {
lualine_a = [
[ "filename" (mkDictItem "path" 1) ]
];
lualine_b = [ "branch" "diff" "diagnostics" ];
lualine_c = [ "lsp_progress" ];
lualine_x = [ "filesize" "filetype" ];
lualine_y = [ "progress" ];
lualine_z = [ "location" "mode" ];
};
};
orgmode.settings = {
org_agenda_files = [ "~/orgs/**/*" ];
org_default_notes_file = "~/orgs/refile.org";
win_split_mode = "tabnew";
org_hide_leading_stars = true;
};
};
}); });
in in
{ {

View file

@ -51,7 +51,7 @@ let
in in
{ {
inherit (lib) importJSON; inherit (lib) importJSON attrByPath;
inherit foldr concatMap; inherit foldr concatMap;
inherit optional getAttrOpt; inherit optional getAttrOpt;
inherit mkLuaHeredoc mkLuaRc; inherit mkLuaHeredoc mkLuaRc;

View file

@ -1,4 +1,6 @@
{ nvim-tree-lua { lib
, plugins ? { }
, nvim-tree-lua
, telescope-nvim , telescope-nvim
, telescope-live-grep-args-nvim , telescope-live-grep-args-nvim
, ... , ...
@ -6,10 +8,14 @@
let let
inherit (builtins) readFile; inherit (builtins) readFile;
nvimTreeLuaSettings = lib.toLua (lib.attrByPath [ "nvimTree" "settings" ] { } plugins);
telescopeSettings = lib.toLua (lib.attrByPath [ "telescope" "settings" ] { } plugins);
in in
{ {
luaConfig = (readFile ./nvim-tree.lua) luaConfig =
+ (readFile ./telescope-nvim.lua); (readFile (lib.substituteAll { src = ./nvim-tree.lua; inherit nvimTreeLuaSettings; }))
+ (readFile (lib.substituteAll { src = ./telescope-nvim.lua; inherit telescopeSettings; }));
plugins = [ nvim-tree-lua ] plugins = [ nvim-tree-lua ]
++ [ telescope-nvim telescope-live-grep-args-nvim ]; ++ [ telescope-nvim telescope-live-grep-args-nvim ];

View file

@ -1,13 +1,5 @@
-- See: https://github.com/kyazdani42/nvim-tree.lua/blob/master/doc/nvim-tree-lua.txt -- See: https://github.com/kyazdani42/nvim-tree.lua/blob/master/doc/nvim-tree-lua.txt
require("nvim-tree").setup(@nvimTreeLuaSettings@)
-- empty setup using defaults
require("nvim-tree").setup({
open_on_setup = true,
renderer = {
group_empty = true,
full_name = true,
},
})
vim.keymap.set("n", "<leader>nt", "<Cmd>NvimTreeToggle<CR>") vim.keymap.set("n", "<leader>nt", "<Cmd>NvimTreeToggle<CR>")
vim.keymap.set("n", "<leader>nf", "<Cmd>NvimTreeFindFile<CR>") vim.keymap.set("n", "<leader>nf", "<Cmd>NvimTreeFindFile<CR>")

View file

@ -1,7 +1,7 @@
-- See: https://github.com/nvim-telescope/telescope.nvim -- See: https://github.com/nvim-telescope/telescope.nvim
local telescope = require("telescope") local telescope = require("telescope")
telescope.setup({}) telescope.setup(@telescopeSettings@)
vim.keymap.set("n", "<leader>ff", "<Cmd>Telescope find_files hidden=true<CR>") vim.keymap.set("n", "<leader>ff", "<Cmd>Telescope find_files hidden=true<CR>")
vim.keymap.set("n", "<leader>fb", "<Cmd>Telescope buffers<CR>") vim.keymap.set("n", "<leader>fb", "<Cmd>Telescope buffers<CR>")

View file

@ -1,4 +1,6 @@
{ nvim-lspconfig { lib
, plugins
, nvim-lspconfig
, nlsp-settings-nvim , nlsp-settings-nvim
, lspsaga-nvim , lspsaga-nvim
, luasnip , luasnip
@ -17,9 +19,12 @@ let
cmp-nvim-lsp # LSP source for nvim-cmp cmp-nvim-lsp # LSP source for nvim-cmp
cmp-luasnip # Snippets source for nvim-cmp cmp-luasnip # Snippets source for nvim-cmp
]; ];
lspConfigServers = lib.toLua (lib.attrByPath [ "lspConfig" "servers" ] [ ] plugins);
lspSagaSettings = lib.toLua (lib.attrByPath [ "lspSaga" "settings" ] { } plugins);
in in
{ {
luaConfig = (readFile ./lspconfig.lua) luaConfig = (readFile (lib.substituteAll { src = ./lspconfig.lua; inherit lspConfigServers lspSagaSettings; }))
+ (readFile ./nvim-cmp.lua); + (readFile ./nvim-cmp.lua);
plugins = lsp plugins = lsp

View file

@ -3,14 +3,7 @@ local saga = require("lspsaga")
local nlsp_settings = require("nlspsettings") local nlsp_settings = require("nlspsettings")
-- See: https://github.com/glepnir/lspsaga.nvim#configuration -- See: https://github.com/glepnir/lspsaga.nvim#configuration
saga.init_lsp_saga({ saga.init_lsp_saga(@lspSagaSettings@)
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>",
})
-- always show signcolumns -- always show signcolumns
vim.opt.signcolumn = "yes" vim.opt.signcolumn = "yes"
@ -64,15 +57,20 @@ nlsp_settings.setup({})
-- See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md -- See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- --
-- Override the default configuration to be applied to all servers -- Override the default configuration to be applied to all servers
lsp_config.util.default_config = vim.tbl_extend("force", lsp_config.util.default_config, { lsp_config.util.default_config = vim.tbl_extend("force", lsp_config.util.default_config, {
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities, capabilities = capabilities,
}) })
-- nix local root_pattern = lsp_config.util.root_pattern
lsp_config.nil_ls.setup({})
for name, settings in pairs(@lspConfigServers@) do
lsp_config[name].setup(settings)
end
--[[
-- js,ts -- js,ts
lsp_config.tsserver.setup({}) lsp_config.tsserver.setup({})
lsp_config.eslint.setup({}) lsp_config.eslint.setup({})
@ -98,3 +96,4 @@ lsp_config.rust_analyzer.setup({
}, },
}, },
}) })
]]--

View file

@ -1,4 +1,5 @@
{ lib { lib
, plugins
, theme , theme
, lualine-nvim , lualine-nvim
, lualine-lsp-progress , lualine-lsp-progress
@ -20,11 +21,12 @@ let
vim.cmd([[colorscheme catppuccin]]) vim.cmd([[colorscheme catppuccin]])
''; '';
lualineSettings = lib.toLua (lib.attrByPath [ "lualine" "settings" ] { } plugins);
lualinePlugins = [ lualine-nvim lualine-lsp-progress ]; lualinePlugins = [ lualine-nvim lualine-lsp-progress ];
in in
{ {
luaConfig = themeConfig luaConfig = themeConfig
+ (readFile ./lualine.lua) + (readFile (lib.substituteAll { src = ./lualine.lua; inherit lualineSettings; }))
+ (lib.optional enableTabby (readFile ./tabby-nvim.lua)); + (lib.optional enableTabby (readFile ./tabby-nvim.lua));
plugins = [ theme ] plugins = [ theme ]

View file

@ -1,16 +1,2 @@
-- See: https://github.com/nvim-lualine/lualine.nvim#default-configuration -- See: https://github.com/nvim-lualine/lualine.nvim#default-configuration
require("lualine").setup({ require("lualine").setup(@lualineSettings@)
options = {
ignore_focus = { "NvimTree" },
},
sections = {
lualine_a = {
{ "filename", path = 1 },
},
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = { "lsp_progress" },
lualine_x = { "filesize", "filetype" },
lualine_y = { "progress" },
lualine_z = { "location", "mode" },
},
})

View file

@ -1,4 +1,5 @@
{ lib { lib
, plugins
, hop-nvim , hop-nvim
, nvim-orgmode , nvim-orgmode
, org-bullets-nvim , org-bullets-nvim
@ -8,10 +9,12 @@
let let
inherit (builtins) readFile; inherit (builtins) readFile;
orgmodeSettings = lib.toLua (lib.attrByPath [ "orgmode" "settings" ] { } plugins);
in in
{ {
luaConfig = readFile ./hop-nvim.lua luaConfig = readFile ./hop-nvim.lua
+ lib.optional enableOrgMode (readFile ./nvim-orgmode.lua); + lib.optional enableOrgMode (readFile (lib.substituteAll { src = ./nvim-orgmode.lua; inherit orgmodeSettings; }));
plugins = [ hop-nvim ] plugins = [ hop-nvim ]
++ lib.optional enableOrgMode [ nvim-orgmode org-bullets-nvim ]; ++ lib.optional enableOrgMode [ nvim-orgmode org-bullets-nvim ];

View file

@ -1,8 +1,3 @@
require("orgmode").setup({ require("orgmode").setup(@orgmodeSettings@)
org_agenda_files = { "~/orgs/**/*" },
org_default_notes_file = "~/orgs/refile.org",
win_split_mode = "tabnew",
org_hide_leading_stars = true,
})
require("org-bullets").setup() require("org-bullets").setup()