diff --git a/flake.lock b/flake.lock index 09a88d8..38b7ebe 100644 --- a/flake.lock +++ b/flake.lock @@ -101,11 +101,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1700678569, - "narHash": "sha256-2Ki+2UvOidxEb3xB4ADqlbPQ2BZOF4uZMR094O8or2I=", + "lastModified": 1700851152, + "narHash": "sha256-3PWITNJZyA3jz5IGREJRfSykM6xSLmD8u5A3WpBCyDM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "8f1180704ac35baded1a74164365ac7cdfba6f38", + "rev": "1216a5ba22a93a4a3a3bfdb4bff0f4727c576fcc", "type": "github" }, "original": { @@ -115,13 +115,29 @@ "type": "github" } }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1701040486, + "narHash": "sha256-vawYwoHA5CwvjfqaT3A5CT9V36Eq43gxdwpux32Qkjw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "45827faa2132b8eade424f6bdd48d8828754341a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nur": { "locked": { - "lastModified": 1700855055, - "narHash": "sha256-QKjcrEntfghcXBsrenDE46OxaF/4YQVStAQfyDOQcPA=", + "lastModified": 1700923974, + "narHash": "sha256-3SWdqep5XzFEuK+5iJkDe/mTIvidS3Gs47W/DVXuRnE=", "owner": "nix-community", "repo": "NUR", - "rev": "ebf2c68214f10ee5b9372ae4960a7b54af514bd3", + "rev": "2644c4a32642a32ea01dc63fd780404c21c82d7a", "type": "github" }, "original": { @@ -137,6 +153,7 @@ "homeage": "homeage", "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable", "nur": "nur" } } diff --git a/flake.nix b/flake.nix index f55f794..5887521 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,7 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nur.url = "github:nix-community/NUR"; home-manager = { url = @@ -21,14 +22,24 @@ nixos-hardware.url = "github:NixOS/nixos-hardware/master"; }; - outputs = - { nixpkgs, home-manager, homeage, agenix, nur, nixos-hardware, ... }: { + outputs = { nixpkgs, nixpkgs-unstable, home-manager, homeage, agenix, nur + , nixos-hardware, ... }: { formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt; - nixosConfigurations.pim = nixpkgs.lib.nixosSystem { + nixosConfigurations.pim = nixpkgs.lib.nixosSystem rec { system = "x86_64-linux"; modules = [ - { nixpkgs.overlays = [ nur.overlay ]; } + { + nixpkgs.overlays = [ + nur.overlay + (final: _prev: { + unstable = import nixpkgs-unstable { + inherit system; + config.allowUnfree = true; + }; + }) + ]; + } ./nixos agenix.nixosModules.default nixos-hardware.nixosModules.lenovo-thinkpad-x260 diff --git a/home-manager/neovim/bufferline.lua b/home-manager/neovim/bufferline.lua index 5d13d9b..ff9b448 100644 --- a/home-manager/neovim/bufferline.lua +++ b/home-manager/neovim/bufferline.lua @@ -1,13 +1,13 @@ -require("bufferline").setup { - options = { - diagnostics = 'nvim_lsp', - diagnostics_indicator = function(count, level, diagnostics_dict, context) - local icon = level:match("error") and " " or " " - return " " .. icon .. count - end, - separator_style = "slant", - hover = {enabled = true, reveal = {'close'}} - } -} +require("bufferline").setup({ + options = { + diagnostics = "nvim_lsp", + diagnostics_indicator = function(count, level, diagnostics_dict, context) + local icon = level:match("error") and " " or " " + return " " .. icon .. count + end, + separator_style = "slant", + hover = { enabled = true, reveal = { "close" } }, + }, +}) -vim.keymap.set('n', 'ft', ":BufferLinePick", {}) +vim.keymap.set("n", "ft", ":BufferLinePick", {}) diff --git a/home-manager/neovim/cmp.lua b/home-manager/neovim/cmp.lua index a42f7ab..62b772b 100644 --- a/home-manager/neovim/cmp.lua +++ b/home-manager/neovim/cmp.lua @@ -1,39 +1,43 @@ -local cmp = require('cmp') -local luasnip = require('luasnip') +local cmp = require("cmp") +local luasnip = require("luasnip") -require('luasnip.loaders.from_vscode').lazy_load() -luasnip.config.setup {} +require("luasnip.loaders.from_vscode").lazy_load() +luasnip.config.setup({}) -cmp.setup { - snippet = {expand = function(args) luasnip.lsp_expand(args.body) end}, - mapping = cmp.mapping.preset.insert { - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete {}, - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true - }, - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, {'i', 's'}), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, {'i', 's'}) - }, - sources = {{name = 'nvim_lsp'}, {name = 'luasnip'}} -} +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete({}), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + sources = { { name = "nvim_lsp" }, { name = "luasnip" } }, +}) diff --git a/home-manager/neovim/default.nix b/home-manager/neovim/default.nix index 08351b5..29c0f68 100644 --- a/home-manager/neovim/default.nix +++ b/home-manager/neovim/default.nix @@ -14,9 +14,9 @@ neofetch gopls terraform-ls - luaformatter - efm-langserver nixfmt + stylua + black ]; plugins = with pkgs.vimPlugins; [ @@ -69,6 +69,11 @@ } nvim-web-devicons lsp-format-nvim + { + plugin = pkgs.unstable.vimPlugins.none-ls-nvim; + type = "lua"; + config = builtins.readFile ./none-ls.lua; + } ]; }; diff --git a/home-manager/neovim/leap.lua b/home-manager/neovim/leap.lua index 9f4ce6b..2b15d73 100644 --- a/home-manager/neovim/leap.lua +++ b/home-manager/neovim/leap.lua @@ -1,4 +1,4 @@ -require('leap').add_default_mappings() +require("leap").add_default_mappings() -- Don't remap 'x' in visual mode. -vim.keymap.del({'x', 'o'}, 'x') -vim.keymap.del({'x', 'o'}, 'X') +vim.keymap.del({ "x", "o" }, "x") +vim.keymap.del({ "x", "o" }, "X") diff --git a/home-manager/neovim/lspconfig.lua b/home-manager/neovim/lspconfig.lua index f4cadb3..603e6a1 100644 --- a/home-manager/neovim/lspconfig.lua +++ b/home-manager/neovim/lspconfig.lua @@ -1,59 +1,58 @@ -require("lsp-format").setup {} +require("lsp-format").setup({}) local on_attach = function(client, bufnr) - local bufmap = function(keys, func) - vim.keymap.set('n', keys, func, {buffer = bufnr}) - end + local bufmap = function(keys, func) + vim.keymap.set("n", keys, func, { buffer = bufnr }) + end - bufmap('r', vim.lsp.buf.rename) - bufmap('a', vim.lsp.buf.code_action) + bufmap("r", vim.lsp.buf.rename) + bufmap("a", vim.lsp.buf.code_action) - bufmap('gd', vim.lsp.buf.definition) - bufmap('gD', vim.lsp.buf.declaration) - bufmap('gI', vim.lsp.buf.implementation) - bufmap('D', vim.lsp.buf.type_definition) + bufmap("gd", vim.lsp.buf.definition) + bufmap("gD", vim.lsp.buf.declaration) + bufmap("gI", vim.lsp.buf.implementation) + bufmap("D", vim.lsp.buf.type_definition) - bufmap('gr', require('telescope.builtin').lsp_references) - bufmap('s', require('telescope.builtin').lsp_document_symbols) - bufmap('S', - require('telescope.builtin').lsp_dynamic_workspace_symbols) + bufmap("gr", require("telescope.builtin").lsp_references) + bufmap("s", require("telescope.builtin").lsp_document_symbols) + bufmap("S", require("telescope.builtin").lsp_dynamic_workspace_symbols) - bufmap('K', vim.lsp.buf.hover) + bufmap("K", vim.lsp.buf.hover) - vim.api.nvim_buf_create_user_command(bufnr, 'Format', - function(_) vim.lsp.buf.format() end, - {}) + vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) + vim.lsp.buf.format() + end, {}) end local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) +capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) -require('neodev').setup() -require'lspconfig'.nil_ls.setup { - on_attach = on_attach, - capabilities = capabilities -} -require'lspconfig'.pyright.setup { - on_attach = on_attach, - capabilities = capabilities -} -require'lspconfig'.gopls.setup { - on_attach = on_attach, - capabilities = capabilities -} -require'lspconfig'.terraformls.setup { - on_attach = on_attach, - capabilities = capabilities -} +require("neodev").setup() +require("lspconfig").nil_ls.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) +require("lspconfig").pyright.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) +require("lspconfig").gopls.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) +require("lspconfig").terraformls.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) -require'lspconfig'.efm.setup { - on_attach = require("lsp-format").on_attach, - init_options = {documentFormatting = true}, - settings = { - languages = { - lua = {{formatCommand = "lua-format -i", formatStdin = true}}, - nix = {{formatCommand = "nixfmt", formatStdin = true}} - } - }, - filetypes = {"lua", "nix"} -} +-- require'lspconfig'.efm.setup { +-- on_attach = require("lsp-format").on_attach, +-- init_options = {documentFormatting = true}, +-- settings = { +-- languages = { +-- lua = {{formatCommand = "lua-format -i", formatStdin = true}}, +-- nix = {{formatCommand = "nixfmt", formatStdin = true}} +-- } +-- }, +-- filetypes = {"lua", "nix"} +-- } diff --git a/home-manager/neovim/none-ls.lua b/home-manager/neovim/none-ls.lua new file mode 100644 index 0000000..47d76a2 --- /dev/null +++ b/home-manager/neovim/none-ls.lua @@ -0,0 +1,51 @@ +-- renamed to none-ls +local null_ls_status_ok, null_ls = pcall(require, "null-ls") +if not null_ls_status_ok then + return +end + +local formatting = null_ls.builtins.formatting +local diagnostics = null_ls.builtins.diagnostics +local code_actions = null_ls.builtins.code_actions + +-- to setup format on save +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + +require("null-ls").setup({ + sources = { + formatting.stylua, + formatting.black, + }, + + -- configure format on save + on_attach = function(current_client, bufnr) + if current_client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ + filter = function(client) + -- only use null-ls for formatting instead of lsp server + return client.name == "null-ls" + end, + bufnr = bufnr, + }) + end, + }) + end + end, +}) + +-- formatting command +vim.api.nvim_create_user_command("Format", function() + vim.lsp.buf.format(nil, 10000) +end, {}) + +vim.keymap.set( + "n", + "fm", + ":Format", + { desc = "Format current buffer (also done on save)", noremap = true, silent = true } +) diff --git a/home-manager/neovim/telescope.lua b/home-manager/neovim/telescope.lua index 66b8346..0dff4b5 100644 --- a/home-manager/neovim/telescope.lua +++ b/home-manager/neovim/telescope.lua @@ -1,17 +1,17 @@ -local builtin = require('telescope.builtin') +local builtin = require("telescope.builtin") -vim.keymap.set('n', 'ff', builtin.find_files, {}) -vim.keymap.set('n', 'fg', builtin.live_grep, {}) -vim.keymap.set('n', 'fb', builtin.buffers, {}) -vim.keymap.set('n', 'fr', builtin.lsp_references, {}) -vim.keymap.set('n', 'fs', builtin.lsp_document_symbols, {}) +vim.keymap.set("n", "ff", builtin.find_files, {}) +vim.keymap.set("n", "fg", builtin.live_grep, {}) +vim.keymap.set("n", "fb", builtin.buffers, {}) +vim.keymap.set("n", "fr", builtin.lsp_references, {}) +vim.keymap.set("n", "fs", builtin.lsp_document_symbols, {}) -require('telescope').setup { - pickers = { - find_files = {theme = "dropdown"}, - live_grep = {theme = "dropdown"}, - buffers = {theme = "dropdown"}, - lsp_references = {theme = "dropdown"}, - lsp_document_symbols = {theme = "dropdown"} - } -} +require("telescope").setup({ + pickers = { + find_files = { theme = "dropdown" }, + live_grep = { theme = "dropdown" }, + buffers = { theme = "dropdown" }, + lsp_references = { theme = "dropdown" }, + lsp_document_symbols = { theme = "dropdown" }, + }, +}) diff --git a/home-manager/neovim/treesitter.lua b/home-manager/neovim/treesitter.lua index d73c59a..1a873cf 100644 --- a/home-manager/neovim/treesitter.lua +++ b/home-manager/neovim/treesitter.lua @@ -1,10 +1,9 @@ -require('nvim-treesitter.configs').setup { - ensure_installed = {}, +require("nvim-treesitter.configs").setup({ + ensure_installed = {}, - auto_install = false, + auto_install = false, - highlight = {enable = true}, - - indent = {enable = true} -} + highlight = { enable = true }, + indent = { enable = true }, +})