home-manager icon indicating copy to clipboard operation
home-manager copied to clipboard

bug: Neovim plugins are built but not linked into config

Open 4jamesccraven opened this issue 1 year ago • 2 comments

Are you following the right branch?

  • [X] My Nixpkgs and Home Manager versions are in sync

Is there an existing issue for this?

  • [X] I have searched the existing issues

Issue description

After the latest update to my config, my plugins are built but are no longer sourced into my init.lua as before. Previously the file symlinked to $HOME/.config/nvim/init.lua generated by programs.neovim.extraLuaConfig would contain a line that would source the config generated to init.vim inside /nix/store. This is no longer the case. Additionally, a .drv file was found for the init.vim that should be generated, but on inspecting the intended output with nix derivation show, I found that it was not generated. All of the plugins were built into the store, but for whatever reason the file (which was in the text body of the derivation file) was not built and was not linked into init.lua. I have attached my neovim.nix as well the flake.lock file that shows the exact builds of home-manager and nixpkgs that causes this issue.

neovim.nix

{ pkgs, ... }:

{

  home-manager.users.jamescraven = {
    programs.neovim = {

      extraPackages = with pkgs; [
        # LSP
        clang-tools
        jdt-language-server
        nixd
        pyright
        rust-analyzer
        sqls
        texlab

        # Clipboard support
        xclip
        wl-clipboard
      ];

      enable = true;
      viAlias = true;
      vimAlias = true;

      ### General config ###
      extraLuaConfig = /*lua*/ ''
        -- Clipboard
        vim.opt.clipboard = 'unnamedplus'
        vim.opt.mouse = 'a'

        -- Tabs
        vim.opt.tabstop = 4
        vim.opt.softtabstop = 4
        vim.opt.shiftwidth = 4
        vim.opt.expandtab = true
        vim.opt.list = true

        -- Line numbers
        vim.opt.number = true
        vim.opt.relativenumber = true

        -- Search config
        vim.opt.incsearch = true
        vim.opt.hlsearch = false
        vim.opt.ignorecase = true
        vim.opt.smartcase = true

        -- Vertical split
        vim.o.splitright = true

        -- Transparent Background
        vim.cmd.highlight({ "Normal", "guibg=NONE", "ctermbg=NONE" })
        vim.cmd.highlight({ "NonText", "guibg=NONE", "ctermbg=NONE" })

        -- Remember last place in buffer
        local lastplace = vim.api.nvim_create_augroup("LastPlace", {})
        vim.api.nvim_clear_autocmds({ group = lastplace })
        vim.api.nvim_create_autocmd("BufReadPost", {
          group = lastplace,
          pattern = { "*" },
          desc = "remember last cursor place",
          callback = function()
            local mark = vim.api.nvim_buf_get_mark(0, '"')
            local lcount = vim.api.nvim_buf_line_count(0)
            if mark[1] > 0 and mark[1] <= lcount then
              pcall(vim.api.nvim_win_set_cursor, 0, mark)
            end
          end,
        })

        -- Set tabsize for *.nix
        vim.cmd([[
          augroup NixTabSettings
            autocmd!
            autocmd FileType nix setlocal tabstop=2 shiftwidth=2 expandtab
          augroup END
        ]])
      '';

      ### plugins ###
      plugins =
      let
        toLua = str: "lua << EOF\n${str}\nEOF\n";
      in
      with pkgs.vimPlugins; [
        {
          plugin = catppuccin-nvim;
          config = "colorscheme catppuccin-frappe";
        }
        {
          plugin = indent-blankline-nvim;
          config = toLua /*lua*/ ''
            require("ibl").setup {
              scope = { enabled = false }
            }
          '';
        }
        {
          plugin = neo-tree-nvim;
          config = toLua /*lua*/ ''
            vim.api.nvim_create_user_command('NT', 'Neotree toggle', {})
            vim.cmd('cnoreabbrev nt NT')

            -- close if last open
            require("neo-tree").setup({
              close_if_last_window = true,
            })
          '';
        }
        cmp-nvim-lsp
        cmp-buffer
        cmp-path
        cmp-cmdline
        cmp-nvim-ultisnips
        {
          plugin = nvim-cmp;
          config = toLua /*lua*/ ''
            local cmp = require'cmp'

            cmp.setup({
              snippet = {
                expand = function(args)
                  vim.fn["UltiSnips#Anon"](args.body)
                end,
              },
              mapping = cmp.mapping.preset.insert ({
                 ['<C-n>'] = cmp.mapping.select_next_item(),
                 ['<C-p>'] = cmp.mapping.select_prev_item(),
                 ['<C-y>'] = cmp.mapping.confirm({ select = true }),
              }),
              sources = cmp.config.sources ({
                { name = 'nvim_lsp'},
                { name = 'buffer'},
                { name = 'path'},
                { name = 'ultisnips'},
              })
            })
          '';
        }
        {
          plugin = nvim-lspconfig;
          config = toLua /*lua*/ ''
            require'lspconfig'.clangd.setup{}
            require'lspconfig'.jdtls.setup{}
            require'lspconfig'.nixd.setup{}
            require'lspconfig'.pyright.setup{}
            require'lspconfig'.rust_analyzer.setup{}
            require'lspconfig'.sqls.setup{}
            require'lspconfig'.texlab.setup{
              settings = {
                texlab = {
                  build = {
                    executable = "latexmk",
                    args = { "-pdf", "-interaction=nonstopmode", "-synctex=1", "%f" },
                    onSave = true,
                  },
                  forwardSearch = {
                    executable = "brave",
                    args = { "--new-tab", "%p" },
                  },
                  chktex = {
                    onOpenAndSave = true,
                    onEdit = false,
                  },
                }
              }
            }
          '';
        }
        {
          plugin = telescope-nvim;
          config = toLua /*lua*/ ''
            -- Rebind commands
            vim.api.nvim_create_user_command('FF', 'Telescope find_files', {})
            vim.cmd('cnoreabbrev ff FF')
            vim.api.nvim_create_user_command('FG', 'Telescope live_grep', {})
            vim.cmd('cnoreabbrev fg FG')

            -- Run on launch
            vim.api.nvim_create_autocmd("VimEnter", {
              callback = function()
                if vim.fn.argv(0) == "" then
                  require("telescope.builtin").find_files()
                  end
              end
            })
          '';
        }
        {
          plugin = (nvim-treesitter.withPlugins (p: [
            p.tree-sitter-bash
            p.tree-sitter-cpp
            p.tree-sitter-java
            p.tree-sitter-json
            p.tree-sitter-latex
            p.tree-sitter-lua
            p.tree-sitter-nix
            p.tree-sitter-python
            p.tree-sitter-rust
            p.tree-sitter-sql
            p.tree-sitter-vim
          ]));
          config = toLua /*lua*/ ''
            require('nvim-treesitter.configs').setup {
              ensure_installed = {},
              auto_install = false,
              highlight = { enable = true },
            }
          '';
        }
        {
          plugin = ultisnips;
          config = ''
            let g:UltiSnipsSnippetDirectories=['/home/jamescraven/nixos/modules/dots/snippets']
            let g:UltiSnipsExpandTrigger = '<tab>'
            let g:UltiSnipsJumpForwardTrigger = '<tab>'
            let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
          '';
        }
        {
          plugin = vim-visual-increment;
          config = ''
            set nrformats=alpha,octal,hex
          '';
        }
      ];

    };
  };

}

flake.lock

{
  "nodes": {
    "home-manager": {
      "inputs": {
        "nixpkgs": [
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1729260213,
        "narHash": "sha256-jAvHoU/1y/yCuXzr2fNF+q6uKmr8Jj2xgAisK4QB9to=",
        "owner": "nix-community",
        "repo": "home-manager",
        "rev": "09a0c0c02953318bf94425738c7061ffdc4cba75",
        "type": "github"
      },
      "original": {
        "owner": "nix-community",
        "ref": "master",
        "repo": "home-manager",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1729070438,
        "narHash": "sha256-KOTTUfPkugH52avUvXGxvWy8ibKKj4genodIYUED+Kc=",
        "owner": "nixos",
        "repo": "nixpkgs",
        "rev": "5785b6bb5eaae44e627d541023034e1601455827",
        "type": "github"
      },
      "original": {
        "owner": "nixos",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "python310-14": {
      "locked": {
        "lastModified": 1723635686,
        "narHash": "sha256-iNYh7Kb0D+MQ8IHM4+8bT1bUS5RNW6gVSDe2yTO1aAk=",
        "owner": "nixos",
        "repo": "nixpkgs",
        "rev": "0cb2fd7c59fed0cd82ef858cbcbdb552b9a33465",
        "type": "github"
      },
      "original": {
        "owner": "nixos",
        "repo": "nixpkgs",
        "rev": "0cb2fd7c59fed0cd82ef858cbcbdb552b9a33465",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "home-manager": "home-manager",
        "nixpkgs": "nixpkgs",
        "python310-14": "python310-14"
      }
    }
  },
  "root": "root",
  "version": 7
}

Maintainer CC

No response

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.6.56, NixOS, 24.11 (Vicuna), 24.11.20241016.5785b6b`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.24.9`
 - channels(root): `""`
 - nixpkgs: `/nix/store/w7nfn4lcfisddz14b0y8n05rjf0dl5lq-source`

4jamesccraven avatar Oct 19 '24 23:10 4jamesccraven

I ran into this issue. After some investigation and talking to a friend I believe this is not a home-manager issue, but actually because of a nixpkgs neovim update, I believe this is the offending commit: https://github.com/NixOS/nixpkgs/commit/2f4291af950f6edbcf2d80610c27380e5112f426 but I was not able to confirm it yet.

rafaelrc7 avatar Oct 20 '24 06:10 rafaelrc7

@rafaelrc7 I tried with that version, but that doesn't seem to be the commit that introduced it. After some testing it seems this commit introduced the issue https://github.com/NixOS/nixpkgs/commit/12dafac23cc3d9998cc5a4ce3485bad1bbba3ae9. I was able to change my flake to point at the parent commit of the problem version to fix my local environment:

 nixpkgs.url = "github:nixos/nixpkgs/11cf80ae321c35132c1aff950f026e9783f06fec";

tmiller avatar Oct 20 '24 22:10 tmiller

Seems like the config attribute of every neovim.plugins item is ignored.

SRachamim avatar Oct 21 '24 07:10 SRachamim

I think this PR fixes this issue: https://github.com/nix-community/home-manager/pull/5976

Testing it locally, it works for me at least!

euank avatar Oct 21 '24 09:10 euank

Seems like the config attribute of every neovim.plugins item is ignored.

All of my type=lua plugin.config attributes seem to make it over to init.lua, but the type=viml ones are lost completely.

svrana avatar Oct 21 '24 15:10 svrana

the change comes indeed fron the nixpkgs change. Behavor of makeNeovimConfig has changed a bit. Can anyone confirm https://github.com/nix-community/home-manager/pull/5976 fixes their issues ? If yes I can merge.

teto avatar Oct 21 '24 21:10 teto

@teto It worked for me.

tmiller avatar Oct 21 '24 21:10 tmiller

The merge of https://github.com/nix-community/home-manager/pull/5976 seems to have fixed the issue for me!

rafaelrc7 avatar Oct 21 '24 23:10 rafaelrc7