diff options
author | Linnnus <[email protected]> | 2023-09-05 20:38:32 +0200 |
---|---|---|
committer | Linnnus <[email protected]> | 2023-09-05 20:38:32 +0200 |
commit | 80006f82905f2567c895cf8737aaf3bf07f9668b (patch) | |
tree | aaacfc4f4327759157429c4b60b6b4a2c659c428 /use-cases/development | |
parent | 7d4ab89f1e6264e124109bf25eafaafdf1aec02a (diff) |
Lots of stuff
Diffstat (limited to 'use-cases/development')
-rw-r--r-- | use-cases/development/default.nix | 6 | ||||
-rw-r--r-- | use-cases/development/git/default.nix (renamed from use-cases/development/git.nix) | 0 | ||||
-rw-r--r-- | use-cases/development/neovim.nix | 60 | ||||
-rw-r--r-- | use-cases/development/neovim/default.nix | 29 | ||||
-rw-r--r-- | use-cases/development/neovim/filetype.nix | 20 | ||||
-rw-r--r-- | use-cases/development/neovim/lsp.nix | 89 | ||||
-rw-r--r-- | use-cases/development/zsh/default.nix (renamed from use-cases/development/zsh.nix) | 5 |
7 files changed, 146 insertions, 63 deletions
diff --git a/use-cases/development/default.nix b/use-cases/development/default.nix index a2c3675..1acffec 100644 --- a/use-cases/development/default.nix +++ b/use-cases/development/default.nix @@ -3,8 +3,8 @@ { imports = [ - ./git.nix - ./neovim.nix - ./zsh.nix + ./git + ./neovim + ./zsh # TODO: move to sysadmin? ]; } diff --git a/use-cases/development/git.nix b/use-cases/development/git/default.nix index 8df44db..8df44db 100644 --- a/use-cases/development/git.nix +++ b/use-cases/development/git/default.nix diff --git a/use-cases/development/neovim.nix b/use-cases/development/neovim.nix deleted file mode 100644 index fb7acf3..0000000 --- a/use-cases/development/neovim.nix +++ /dev/null @@ -1,60 +0,0 @@ - -# This file contains the HM configuration options for Neovim for the user -# 'linus'. Don't know him. - -{ pkgs, lib, ... }: - -{ - programs.neovim = { - enable = true; - - # Wrap neovim with LSP dependencies. - # TODO: Build fails with permission error. What? I hate computers... - # package = - # let - # base = pkgs.neovim-unwrapped; - # deps = with pkgs; [ pyright ]; - # neovim' = pkgs.runCommandLocal "neovim-with-deps" { - # buildInputs = [ pkgs.makeWrapper ]; - # } '' - # mkdir $out - # # Link every top-level folder from pkgs.hello to our new target - # ln -s ${base}/* $out - # # Except the bin folder - # rm $out/bin - # mkdir $out/bin - # # We create the bin folder ourselves and link every binary in it - # ln -s ${base}/bin/* $out/bin - # # Except the nvim binary - # rm $out/bin/nvim - # # Because we create this ourself, by creating a wrapper - # makeWrapper ${base}/bin/nvim $out/bin/nvim \ - # --prefix PATH : ${lib.makeBinPath deps} - # ''; - # in - # neovim'; - - plugins = with pkgs.vimPlugins; [ - { - plugin = nvim-lspconfig; - type = "lua"; - config = '' - local lspconfig = require("lspconfig"); - lspconfig.pyright.setup { } - ''; - } - ]; - - # Typing `vi`, `vim`, or `vimdiff` will also run neovim. - viAlias = true; - vimAlias = true; - vimdiffAlias = true; - }; - - # Set Neovim as the default editor. - home.sessionVariables.EDITOR = "nvim"; - home.sessionVariables.VISUAL = "nvim"; - - # Use neovim as man pager. - home.sessionVariables.MANPAGER = "nvim +Man!"; -} diff --git a/use-cases/development/neovim/default.nix b/use-cases/development/neovim/default.nix new file mode 100644 index 0000000..5c265b8 --- /dev/null +++ b/use-cases/development/neovim/default.nix @@ -0,0 +1,29 @@ +# This file contains the HM configuration options for Neovim. + +{ pkgs, lib, ... }: + +{ + imports = + [ + ./lsp.nix + ./filetype.nix + ]; + + programs.neovim = { + enable = true; + + # Typing `vi`, `vim`, or `vimdiff` will also run neovim. + viAlias = true; + vimAlias = true; + vimdiffAlias = true; + }; + + # Set Neovim as the default editor. + home.sessionVariables.EDITOR = "nvim"; + home.sessionVariables.VISUAL = "nvim"; + + # Use neovim as man pager. + home.sessionVariables.MANPAGER = "nvim +Man!"; +} + +# vi: foldmethod=marker diff --git a/use-cases/development/neovim/filetype.nix b/use-cases/development/neovim/filetype.nix new file mode 100644 index 0000000..66d5e68 --- /dev/null +++ b/use-cases/development/neovim/filetype.nix @@ -0,0 +1,20 @@ +# This module configures various syntax/filetype plugins for Neovim. + +{ pkgs, ... }: + +let + vim-noweb = pkgs.vimUtils.buildVimPlugin { + pname = "vim-noweb"; + version = "26-08-2023"; # day of retrieval + src = pkgs.fetchzip { + url = "https://metaed.com/papers/vim-noweb/vim-noweb.tgz"; + hash = "sha256-c5eUZiKIjAfjJ33l821h5DjozMpMf0CaK03QIkSUfxg="; + }; + }; +in +{ + programs.neovim.plugins = with pkgs.vimPlugins; [ + vim-nix + vim-noweb + ]; +} diff --git a/use-cases/development/neovim/lsp.nix b/use-cases/development/neovim/lsp.nix new file mode 100644 index 0000000..0c7321d --- /dev/null +++ b/use-cases/development/neovim/lsp.nix @@ -0,0 +1,89 @@ +# This module sets up LSP server configurations for Neovim. It is waaay +# overcomplicated as it kind of turned into an experiment in generating Lua +# code from a Nix attrset. + +{ pkgs, lib, ... }: + +let + servers = { + pyright.cmd = [ "${pkgs.pyright}/bin/pyright-langserver" ]; + }; + defaultConfig = { + flags.debounce_text_changes = 150; + }; + combinedConfig = lib.mapAttrs (name: value: value // defaultConfig) servers; + + nixToLua = s: + if builtins.isAttrs s then + let + renderAttr = name: value: "[ [==========[" + name + "]==========] ] = " + (nixToLua value); + attrsList = map (name: renderAttr name s.${name}) (lib.attrNames s); + attrsListStr = lib.concatStringsSep ", " attrsList; + in + "{ ${attrsListStr} }" + else if builtins.isList s then + "{ " + (lib.concatStringsSep ", " (map nixToLua s)) + " }" + else if builtins.isString s then + # Oh boy I sure hope `s` doesn't contain "]==========]". + "[==========[" + s + "]==========]" + else if builtins.isInt s || builtins.isFloat s then + toString s + else + throw "Cannot convert ${builtins.typeOf s} to Lua value!"; + combinedConfigStr = nixToLua combinedConfig; +in +{ + programs.neovim.plugins = [ + { + plugin = pkgs.vimPlugins.nvim-lspconfig; + type = "lua"; + config = '' + local lspconfig = require("lspconfig") + local util = require("lspconfig.util") + + -- Mappings. + -- See `:help vim.diagnostic.*` for documentation on any of the below functions + local opts = { noremap=true, silent=true } + vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, opts) + vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) + vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) + vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, opts) + + -- Use an on_attach function to only map the following keys + -- after the language server attaches to the current buffer + local on_attach = function(client, bufnr) + -- Enable completion triggered by <c-x><c-o> + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', '<leader>wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', '<leader>f', function() vim.lsp.buf.format { async = true } end, bufopts) + vim.keymap.set('n', '<leader>s', function() vim.cmd[[ClangdSwitchSourceHeader]] end, bufopts) + end + + -- Use a loop to conveniently call 'setup' on multiple servers and + -- map buffer local keybindings when the language server attaches + local servers = ${combinedConfigStr}; + for server, config in pairs(servers) do + config.on_attach = on_attach; -- inject lua event handler; not elegant! + lspconfig[server].setup(config) + end + ''; + } + ]; +} diff --git a/use-cases/development/zsh.nix b/use-cases/development/zsh/default.nix index 4db241d..ac88554 100644 --- a/use-cases/development/zsh.nix +++ b/use-cases/development/zsh/default.nix @@ -11,4 +11,9 @@ dotDir = ".config/zsh"; history.path = config.xdg.cacheHome + "/zsh/history"; }; + + programs.fzf = { + enable = true; + enableZshIntegration = true; + }; } |