Specify the order in which lua files are evaluated when configuring neovim

I’m using home-manager to manage my dotfiles and binaries and I’m having issues properly configuring my neovim plugins.

This is my nix file for configuring neovim via home manager:

{ vimPlugins }:

let
toLua = str: “lua << EOF\n${str}\nEOF\n”;
toLuaFile = file: “lua << EOF\n${builtins.readFile file}\nEOF\n”;
in
{
enable = true;
defaultEditor = true;
viAlias = true;
vimAlias = true;
vimdiffAlias = true;
extraLuaConfig = ‘’
${builtins.readFile ./options.lua}
‘’;

plugins = with vimPlugins; [
{
plugin = hop-nvim;
config = toLuaFile ./hop.lua;
}
{
plugin = telescope-nvim;
config = toLuaFile ./telescope.lua;
}
telescope-fzf-native-nvim
telescope-ui-select-nvim

vim-nix
vim-nix
plenary-nvim
nvim-web-devicons

];
}

– Telescope specific config file:
require(‘telescope’).setup({
extensions = {
fzf = {
fuzzy = true, – false will only do exact matching
override_generic_sorter = true, – override the generic sorter
override_file_sorter = true, – override the file sorter
case_mode = “smart_case”, – or “ignore_case” or “respect_case”
},
[‘ui-select’] = {
require(‘telescope.themes’).get_dropdown(),
}
}
})

local opts = { noremap = true, silent = true }

– See :help telescope.builtin
local builtin = require ‘telescope.builtin’

vim.keymap.set(‘n’, ‘zf’, builtin.find_files, { desc = ‘[S]earch [F]iles’ })

The issue is that my plugins are pulled in and configured before my options.lua file is, which is where my leader is defined. So the following mapping doesn’t work:
vim.keymap.set(‘n’, ‘zf’, builtin.find_files, { desc = ‘[S]earch [F]iles’ })

How can I tell nix to pull in my options config and then my plugins and configure?

Hi, I just made an account to comment because I had your exact issue and I feel your pain. I got stuck here too.

This is what I did:

  programs.neovim =
  let
    toLua = str: "lua << EOF\n${str}\nEOF\n";
    toLuaFile = file: "lua << EOF\n${builtins.readFile file}\nEOF\n";
  in
  {

    ...

    # packages required by neovim
    extraPackages = with pkgs; [
      # language servers, etc here
    ];

    plugins = with pkgs.vimPlugins; [
      # dependencies
      nvim-web-devicons
      plenary-nvim
      telescope-fzf-native-nvim

      {
        plugin = gruvbox-nvim;
        config = toLuaFile ./nvim/plugin/gruvbox.lua;
      }

      telescope-nvim
      nvim-treesitter.withAllGrammars

    ];

    extraLuaConfig = ''
      ${builtins.readFile ./nvim/set.lua}
      ${builtins.readFile ./nvim/remap.lua}
      ${builtins.readFile ./nvim/plugin/telescope.lua}
    '';
  };

set.lua is Vim option stuff, remap is my keymap file for normal vim stuff. config works for anything but adding keymaps, it seems. I’m also not 100% on how I want to handle dependencies, so I just started throwing everything up top like that so far.

Thank you! Funny enough this is exactly what I ended up doing.

1 Like

vimjoyer is doing great work, glad to see you following along with him.

Tip for samueljoli to help your post readability, you can use the discourse code block tag: ``` to denote a code block like so:

{
  my config code block
}
1 Like