From ea2231f6150c1047a0d0c379f6330fcb29877306 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sat, 19 Nov 2022 00:56:53 +0300 Subject: [PATCH] integrate with nix2lua --- default.nix | 12 ++-- flake.lock | 87 +++++++++++++++++++++++------ flake.nix | 69 +++++++++++++++++++++-- lib.nix | 2 +- plugins/explorer/default.nix | 12 +++- plugins/explorer/nvim-tree.lua | 10 +--- plugins/explorer/telescope-nvim.lua | 2 +- plugins/lsp/default.nix | 9 ++- plugins/lsp/lspconfig.lua | 19 +++---- plugins/theme/default.nix | 4 +- plugins/theme/lualine.lua | 16 +----- plugins/ux/default.nix | 5 +- plugins/ux/nvim-orgmode.lua | 7 +-- 13 files changed, 178 insertions(+), 76 deletions(-) diff --git a/default.nix b/default.nix index 933b3c7..3846a93 100644 --- a/default.nix +++ b/default.nix @@ -6,19 +6,23 @@ , vimAlias ? false , grammarFileTypes ? [ "nix" ] , theme ? { } +, plugins ? { } , wrapNeovim , neovim-unwrapped , tree-sitter , neovimPlugins , lib +, toLua +, substituteAll , ... }: let inherit (builtins) catAttrs isFunction readFile; - myLib = import ./lib.nix { inherit lib; }; + myLib = import ./lib.nix { inherit lib; } // { inherit substituteAll toLua; }; pluginParams = neovimPlugins // { + inherit plugins; inherit tree-sitter grammarFileTypes; inherit enableDevIcons enableTabby enableOrgMode; themeCfg = theme; @@ -29,7 +33,7 @@ let if isFunction op then op pluginParams else import op pluginParams; callPlugins = list: map callPlugin list; - plugins = callPlugins [ + pluginsSettings = callPlugins [ ./plugins/config ./plugins/syntax ./plugins/git @@ -41,11 +45,11 @@ let ]; basePlugins = [ neovimPlugins.plenary-nvim ]; - customPlugins = catAttrs "plugins" plugins; + customPlugins = catAttrs "plugins" pluginsSettings; allPlugins = basePlugins ++ customPlugins; basicConfigs = map readFile [ ./config/basic.lua ]; - pluginConfigs = catAttrs "luaConfig" plugins; + pluginConfigs = catAttrs "luaConfig" pluginsSettings; allConfigs = basicConfigs ++ pluginConfigs; in wrapNeovim neovim-unwrapped { diff --git a/flake.lock b/flake.lock index 07f7055..be47ed5 100644 --- a/flake.lock +++ b/flake.lock @@ -51,6 +51,36 @@ "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": { "flake": false, "locked": { @@ -170,7 +200,42 @@ "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": { + "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": { "lastModified": 1667969101, "narHash": "sha256-GL53T705HO7Q/KVfbb5STx8AxFs8YgaGY8pvAZC+O7U=", @@ -342,6 +407,7 @@ "cmp-luasnip": "cmp-luasnip", "cmp-nvim-lsp": "cmp-nvim-lsp", "editorconfig-nvim": "editorconfig-nvim", + "flake-utils": "flake-utils", "gitsigns-nvim": "gitsigns-nvim", "hop-nvim": "hop-nvim", "lspsaga-nvim": "lspsaga-nvim", @@ -349,7 +415,8 @@ "lualine-nvim": "lualine-nvim", "luasnip": "luasnip", "neoformat": "neoformat", - "nixpkgs": "nixpkgs", + "nix2lua": "nix2lua", + "nixpkgs": "nixpkgs_2", "nlsp-settings-nvim": "nlsp-settings-nvim", "nvim-cmp": "nvim-cmp", "nvim-lspconfig": "nvim-lspconfig", @@ -362,8 +429,7 @@ "tabby-nvim": "tabby-nvim", "telescope-live-grep-args-nvim": "telescope-live-grep-args-nvim", "telescope-nvim": "telescope-nvim", - "theme": "theme", - "utils": "utils" + "theme": "theme" } }, "tabby-nvim": { @@ -433,21 +499,6 @@ "rev": "9ac18414f0446478024b19018d73b7ea14f6fc96", "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", diff --git a/flake.nix b/flake.nix index 3d176b6..d88538f 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,9 @@ { inputs = { 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-nvim = { @@ -158,7 +160,7 @@ }; }; - outputs = inputs @ { self, nixpkgs, utils, ... }: + outputs = inputs @ { self, nixpkgs, flake-utils, nix2lua, ... }: let inputPlugins = [ "plenary-nvim" @@ -219,21 +221,78 @@ { overlays = { 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 pkgs = import nixpkgs { inherit system; }; - neovim = pkgs.callPackage self (mkNvimPlugins pkgs); + neovim = pkgs.callPackage self (mkNvimPlugins pkgs // nix2lua.lib); testNeovim = (neovim.override { enableDevIcons = true; enableTabby = true; enableOrgMode = true; 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 = ""; }; + definition_action_keys = { quit = ""; }; + rename_action_quit = ""; + }; + 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 { diff --git a/lib.nix b/lib.nix index 84da26f..6c7ecaf 100644 --- a/lib.nix +++ b/lib.nix @@ -51,7 +51,7 @@ let in { - inherit (lib) importJSON; + inherit (lib) importJSON attrByPath; inherit foldr concatMap; inherit optional getAttrOpt; inherit mkLuaHeredoc mkLuaRc; diff --git a/plugins/explorer/default.nix b/plugins/explorer/default.nix index b8c880c..a3bdffd 100644 --- a/plugins/explorer/default.nix +++ b/plugins/explorer/default.nix @@ -1,4 +1,6 @@ -{ nvim-tree-lua +{ lib +, plugins ? { } +, nvim-tree-lua , telescope-nvim , telescope-live-grep-args-nvim , ... @@ -6,10 +8,14 @@ let inherit (builtins) readFile; + + nvimTreeLuaSettings = lib.toLua (lib.attrByPath [ "nvimTree" "settings" ] { } plugins); + telescopeSettings = lib.toLua (lib.attrByPath [ "telescope" "settings" ] { } plugins); in { - luaConfig = (readFile ./nvim-tree.lua) - + (readFile ./telescope-nvim.lua); + luaConfig = + (readFile (lib.substituteAll { src = ./nvim-tree.lua; inherit nvimTreeLuaSettings; })) + + (readFile (lib.substituteAll { src = ./telescope-nvim.lua; inherit telescopeSettings; })); plugins = [ nvim-tree-lua ] ++ [ telescope-nvim telescope-live-grep-args-nvim ]; diff --git a/plugins/explorer/nvim-tree.lua b/plugins/explorer/nvim-tree.lua index ea08083..ab1a52d 100644 --- a/plugins/explorer/nvim-tree.lua +++ b/plugins/explorer/nvim-tree.lua @@ -1,13 +1,5 @@ -- See: https://github.com/kyazdani42/nvim-tree.lua/blob/master/doc/nvim-tree-lua.txt - --- empty setup using defaults -require("nvim-tree").setup({ - open_on_setup = true, - renderer = { - group_empty = true, - full_name = true, - }, -}) +require("nvim-tree").setup(@nvimTreeLuaSettings@) vim.keymap.set("n", "nt", "NvimTreeToggle") vim.keymap.set("n", "nf", "NvimTreeFindFile") diff --git a/plugins/explorer/telescope-nvim.lua b/plugins/explorer/telescope-nvim.lua index 4dfe19b..7786d70 100644 --- a/plugins/explorer/telescope-nvim.lua +++ b/plugins/explorer/telescope-nvim.lua @@ -1,7 +1,7 @@ -- See: https://github.com/nvim-telescope/telescope.nvim local telescope = require("telescope") -telescope.setup({}) +telescope.setup(@telescopeSettings@) vim.keymap.set("n", "ff", "Telescope find_files hidden=true") vim.keymap.set("n", "fb", "Telescope buffers") diff --git a/plugins/lsp/default.nix b/plugins/lsp/default.nix index 2eefce3..e174180 100644 --- a/plugins/lsp/default.nix +++ b/plugins/lsp/default.nix @@ -1,4 +1,6 @@ -{ nvim-lspconfig +{ lib +, plugins +, nvim-lspconfig , nlsp-settings-nvim , lspsaga-nvim , luasnip @@ -17,9 +19,12 @@ let cmp-nvim-lsp # LSP 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 { - luaConfig = (readFile ./lspconfig.lua) + luaConfig = (readFile (lib.substituteAll { src = ./lspconfig.lua; inherit lspConfigServers lspSagaSettings; })) + (readFile ./nvim-cmp.lua); plugins = lsp diff --git a/plugins/lsp/lspconfig.lua b/plugins/lsp/lspconfig.lua index c939c87..1c32408 100644 --- a/plugins/lsp/lspconfig.lua +++ b/plugins/lsp/lspconfig.lua @@ -3,14 +3,7 @@ local saga = require("lspsaga") local nlsp_settings = require("nlspsettings") -- See: https://github.com/glepnir/lspsaga.nvim#configuration -saga.init_lsp_saga({ - border_style = "rounded", - symbol_in_winbar = { enable = false }, - code_action_lightbulb = { enable = false }, - code_action_keys = { quit = "" }, - definition_action_keys = { quit = "" }, - rename_action_quit = "", -}) +saga.init_lsp_saga(@lspSagaSettings@) -- always show signcolumns vim.opt.signcolumn = "yes" @@ -64,15 +57,20 @@ nlsp_settings.setup({}) -- See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md -- + -- Override the default configuration to be applied to all servers lsp_config.util.default_config = vim.tbl_extend("force", lsp_config.util.default_config, { on_attach = on_attach, capabilities = capabilities, }) --- nix -lsp_config.nil_ls.setup({}) +local root_pattern = lsp_config.util.root_pattern +for name, settings in pairs(@lspConfigServers@) do + lsp_config[name].setup(settings) +end + +--[[ -- js,ts lsp_config.tsserver.setup({}) lsp_config.eslint.setup({}) @@ -98,3 +96,4 @@ lsp_config.rust_analyzer.setup({ }, }, }) +]]-- diff --git a/plugins/theme/default.nix b/plugins/theme/default.nix index f558647..54283b7 100644 --- a/plugins/theme/default.nix +++ b/plugins/theme/default.nix @@ -1,4 +1,5 @@ { lib +, plugins , theme , lualine-nvim , lualine-lsp-progress @@ -20,11 +21,12 @@ let vim.cmd([[colorscheme catppuccin]]) ''; + lualineSettings = lib.toLua (lib.attrByPath [ "lualine" "settings" ] { } plugins); lualinePlugins = [ lualine-nvim lualine-lsp-progress ]; in { luaConfig = themeConfig - + (readFile ./lualine.lua) + + (readFile (lib.substituteAll { src = ./lualine.lua; inherit lualineSettings; })) + (lib.optional enableTabby (readFile ./tabby-nvim.lua)); plugins = [ theme ] diff --git a/plugins/theme/lualine.lua b/plugins/theme/lualine.lua index f04993b..f9d15a9 100644 --- a/plugins/theme/lualine.lua +++ b/plugins/theme/lualine.lua @@ -1,16 +1,2 @@ -- See: https://github.com/nvim-lualine/lualine.nvim#default-configuration -require("lualine").setup({ - 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" }, - }, -}) +require("lualine").setup(@lualineSettings@) diff --git a/plugins/ux/default.nix b/plugins/ux/default.nix index 6e025d0..bf1f64a 100644 --- a/plugins/ux/default.nix +++ b/plugins/ux/default.nix @@ -1,4 +1,5 @@ { lib +, plugins , hop-nvim , nvim-orgmode , org-bullets-nvim @@ -8,10 +9,12 @@ let inherit (builtins) readFile; + + orgmodeSettings = lib.toLua (lib.attrByPath [ "orgmode" "settings" ] { } plugins); in { 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 ] ++ lib.optional enableOrgMode [ nvim-orgmode org-bullets-nvim ]; diff --git a/plugins/ux/nvim-orgmode.lua b/plugins/ux/nvim-orgmode.lua index dc3e168..12f8764 100644 --- a/plugins/ux/nvim-orgmode.lua +++ b/plugins/ux/nvim-orgmode.lua @@ -1,8 +1,3 @@ -require("orgmode").setup({ - org_agenda_files = { "~/orgs/**/*" }, - org_default_notes_file = "~/orgs/refile.org", - win_split_mode = "tabnew", - org_hide_leading_stars = true, -}) +require("orgmode").setup(@orgmodeSettings@) require("org-bullets").setup()