From 80006f82905f2567c895cf8737aaf3bf07f9668b Mon Sep 17 00:00:00 2001 From: Linnnus Date: Tue, 5 Sep 2023 20:38:32 +0200 Subject: Lots of stuff --- hosts/ahmed/configuration.nix | 2 + use-cases/development/default.nix | 6 +-- use-cases/development/git.nix | 18 ------- use-cases/development/git/default.nix | 18 +++++++ use-cases/development/neovim.nix | 60 --------------------- use-cases/development/neovim/default.nix | 29 ++++++++++ use-cases/development/neovim/filetype.nix | 20 +++++++ use-cases/development/neovim/lsp.nix | 89 +++++++++++++++++++++++++++++++ use-cases/development/zsh.nix | 14 ----- use-cases/development/zsh/default.nix | 19 +++++++ 10 files changed, 180 insertions(+), 95 deletions(-) delete mode 100644 use-cases/development/git.nix create mode 100644 use-cases/development/git/default.nix delete mode 100644 use-cases/development/neovim.nix create mode 100644 use-cases/development/neovim/default.nix create mode 100644 use-cases/development/neovim/filetype.nix create mode 100644 use-cases/development/neovim/lsp.nix delete mode 100644 use-cases/development/zsh.nix create mode 100644 use-cases/development/zsh/default.nix diff --git a/hosts/ahmed/configuration.nix b/hosts/ahmed/configuration.nix index 7d7afcb..530ad36 100644 --- a/hosts/ahmed/configuration.nix +++ b/hosts/ahmed/configuration.nix @@ -58,6 +58,8 @@ networking.wireless.enable = true; networking.wireless.networks."Rumpenettet_Guest".psk = "Rumpenerglad"; # NOCOMMIT + nix.settings.experimental-features = [ "nix-command" ]; + # This value determines the NixOS release from which the default # settings for stateful data, like file locations and database versions # on your system were taken. It's perfectly fine and recommended to leave 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.nix deleted file mode 100644 index 8df44db..0000000 --- a/use-cases/development/git.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ ... }: - -{ - programs.git = { - enable = true; - - # Set privacy-respecting user information. - userName = "Linnnus"; - userEmail = "linnnus@users.noreply.github.com"; - }; - - home.shellAliases = { - gs = "git status"; - gd = "git diff"; - gc = "git commit"; - gap = "git add --patch"; - }; -} diff --git a/use-cases/development/git/default.nix b/use-cases/development/git/default.nix new file mode 100644 index 0000000..8df44db --- /dev/null +++ b/use-cases/development/git/default.nix @@ -0,0 +1,18 @@ +{ ... }: + +{ + programs.git = { + enable = true; + + # Set privacy-respecting user information. + userName = "Linnnus"; + userEmail = "linnnus@users.noreply.github.com"; + }; + + home.shellAliases = { + gs = "git status"; + gd = "git diff"; + gc = "git commit"; + gap = "git add --patch"; + }; +} 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', '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', '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 + 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', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) + vim.keymap.set('n', '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.nix deleted file mode 100644 index 4db241d..0000000 --- a/use-cases/development/zsh.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ pkgs, config, ... }: - -{ - programs.zsh = { - enable = true; - - defaultKeymap = "viins"; - - # Feeble attempt at cleaning up home directory. - # TODO: dotDir = (pathRelativeTo config.xdg.configHome config.home) + "/zsh"; - dotDir = ".config/zsh"; - history.path = config.xdg.cacheHome + "/zsh/history"; - }; -} diff --git a/use-cases/development/zsh/default.nix b/use-cases/development/zsh/default.nix new file mode 100644 index 0000000..ac88554 --- /dev/null +++ b/use-cases/development/zsh/default.nix @@ -0,0 +1,19 @@ +{ pkgs, config, ... }: + +{ + programs.zsh = { + enable = true; + + defaultKeymap = "viins"; + + # Feeble attempt at cleaning up home directory. + # TODO: dotDir = (pathRelativeTo config.xdg.configHome config.home) + "/zsh"; + dotDir = ".config/zsh"; + history.path = config.xdg.cacheHome + "/zsh/history"; + }; + + programs.fzf = { + enable = true; + enableZshIntegration = true; + }; +} -- cgit v1.2.3