nix-community / nixvim

Configure Neovim with Nix! [maintainers=@GaetanLepage, @traxys, @mattsturgeon, @khaneliman]
https://nix-community.github.io/nixvim
MIT License
1.7k stars 262 forks source link

error: attribute 'cmp-ai' missing #1859

Closed JackPala closed 3 months ago

JackPala commented 3 months ago

Running nix darwin

{ pkgs, lib, ... }:
let
  nixvim = import (builtins.fetchGit {
    url = "https://github.com/nix-community/nixvim";
    # If you are not running an unstable channel of nixpkgs, select the corresponding branch of nixvim.
    # ref = "nixos-23.05";
  });
in
{
  imports = [
    # For home-manager
    #nixvim.homeManagerModules.nixvim
    # For NixOS
    #nixvim.nixosModules.nixvim
    # For nix-darwin
    nixvim.nixDarwinModules.nixvim
  ];

  programs.nixvim.enable = true;

  programs.nixvim = {
   # plugins.lightline.enable = true;
   # plugins.lightline.colorscheme = "solarized";
   # plugins.copilot-vim.enable = true;
   # plugins.cmp-git.enable = true;
  };

  # extraPlugins = with pkgs.vimPlugins; [ copilot.vim ];

}

I tried commenting out the plugins to ensure that it isn't on a plugin..

But this is the error that I get?

~/.nixpkgs 7.8s ❱ darwin-rebuild switch                                                                                                                                     12:42:14
building the system configuration...
error:
       … while evaluating the attribute 'value'

         at /nix/store/cwqvlzisg6qbgyjycq9xk4a2hzlzj6sp-nixpkgs/nixpkgs/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       … while calling the 'addErrorContext' builtin

         at /nix/store/cwqvlzisg6qbgyjycq9xk4a2hzlzj6sp-nixpkgs/nixpkgs/lib/modules.nix:809:17:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |                 ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'cmp-ai' missing

       at /nix/store/6qvfd29dri6fdadvia14gi1gy0by7qcv-source/plugins/completion/cmp/sources/_mk-cmp-plugin.nix:11:20:

           10|   sourceName,
           11|   defaultPackage ? pkgs.vimPlugins.${pluginName},
             |                    ^
           12|   maintainers ? [ lib.maintainers.GaetanLepage ],
       Did you mean one of cmp-dap, cmp-git or cmp-rg?
MattSturgeon commented 3 months ago

Are you using the main nixvim branch with a stable version of nixpkgs?

JackPala commented 3 months ago

Are you using the main nixvim branch with a stable version of nixpkgs?

I have not specified ref= at all since it's on MacOS Darwin

darwin https://github.com/LnL7/nix-darwin/archive/master.tar.gz

is the result of nix-channel --list

MattSturgeon commented 3 months ago

I'm more used to dealing with flakes, but essentially if something is missing from pkgs that means your nixpkgs channel is out of sync with ours.

Usually this happens when someone uses nixvim's main branch with the nixos-24.05 branch, but it can also happen if your nixpkgs channel is out of date (needs updating) or even too up to date and we haven't adapted to some nixpkgs changes yet.

JackPala commented 3 months ago

If I am using the official darwin nix channel for MacOS arm64, then does that mean that nixvim is currently broken for mac?

MattSturgeon commented 3 months ago

Does it work if you use nixvim's nixos-24.05 branch?

I don't think nixpkgs has system-specific channels, per-se, so that shouldn't matter.

How do you configure & manage your nixpkgs channel when using nix-darwin?

JackPala commented 3 months ago

On my nixOS machine (24.05) I have the same config but with ref = "nixos-24.05"; and nixvim.nixosModules.nixvim

And it seems to work perfectly. I just rebuilt my NixOS machine to make sure and it seems to be going fine.

This cmp-ai error only seems to be happening on Nix-Darwin

JackPala commented 3 months ago

How do you configure & manage your nixpkgs channel when using nix-darwin?

Outside of nix-channel --list the only other thing I have is

  # Used for backwards compatibility, please read the changelog before changing.
  # $ darwin-rebuild changelog
  system.stateVersion = 4;

in the darwin config. I did an install with the official darwin install and that's it

MattSturgeon commented 3 months ago

Ok, I think there's a few unrelated things being mixed up here.

I'm only taking about your nixpkgs channel. nix-darwin etc shouldn't be a factor here.

First, you can try nix-channel --update to ensure you're using an up-to-date channel.

Next, try using nixvim's stable branch.

Otherwise can you share the output of nix-channel --list?

JackPala commented 3 months ago

Removing all nixvim stuff from my config lets me rebuild darwin without issue

setting nixvim stable branch by using ref = "main"; yields the same error

nix-channel --update and a rebuild yields the same error as well

here is nix-channel --list :

~/.nixpkgs 2.2s | 1 ❱ nix-channel --list                                                                                                                                    19:35:19
darwin https://github.com/LnL7/nix-darwin/archive/master.tar.gz
~/.nixpkgs ❱
JackPala commented 3 months ago

Update: It has now begun throwing the same error on NixOS systems:

building the system configuration...
error:
       … while calling the 'head' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/attrsets.nix:1575:11:

         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'cmp-ai' missing

       at /nix/store/vvggmmy38y09c1ny0402ai31agkn08sw-source/plugins/completion/cmp/sources/_mk-cmp-plugin.nix:11:20:

           10|   sourceName,
           11|   defaultPackage ? pkgs.vimPlugins.${pluginName},
             |                    ^
           12|   maintainers ? [ lib.maintainers.GaetanLepage ],
       Did you mean one of cmp-dap, cmp-git or cmp-rg?
JackPala commented 3 months ago

So now the currently effected versions are:

Darwin latest ARM64
NixOS x64 24.05
JackPala commented 3 months ago

So after some research it appears that cmp-ai is a remote code completion plugin for AI. I currently have all AI disabled in the config during the rebuild so no idea why it would be calling for a plugin that I am not using.

MattSturgeon commented 3 months ago

So after some research it appears that cmp-ai is a remote code completion plugin for AI. I currently have all AI disabled in the config during the rebuild so no idea why it would be calling for a plugin that I am not using.

To evaluate nixvim's modules all packages must exist in your nixpkgs channel, even if the plugins related to the package in question is not enabled.

So now the currently effected versions are: NixOS x64 24.05

If you're using nixvim's main branch with nixpkgs's nixos-24.05 branch, that is expected. You need to use nixvim's nixos-24.05 branch when using nixpkgs 24.05.

I'm unsure how to help you on nix-darwin because I'm unfamiliar with the platform, but the same principle applies.

JackPala commented 3 months ago

So adding

ref = "nixos-24.05"; to the nixvim.nix file did fix that for my NixOS 24.05 servers they now work perfectly.

I'll do some digging on what branch will work with Darwin, as I suspect darwin may be using NixOS packages but the darwin-arm64 versions of those packages as evidenced by the fact that Nixpkgs search has a platforms section:

Screenshot 2024-07-18 at 11 01 50 AM
JackPala commented 3 months ago

Okay so after some testing, in darwin MacOS I was able to get this to work by also defining

ref= "nixos-24.05"; which let it compile and run without errors. This may be because darwin is using the 24.05 repo despite the channel list just showing the master.tar.gz archive

malik-n commented 2 months ago

I am having the exact same problem even though I am not using it on macOS but on NixOS and NixOS-WSL.

There already seems to be a solution but I dont really understand how to implement. @JackPala would you explain where to put ref= "nixos-24.05"; exactly?

MattSturgeon commented 2 months ago

I am having the exact same problem even though I am not using it on macOS but on NixOS and NixOS-WSL.

@malik-n you might be better off opening a fresh discussion or reaching out on our matrix chennel.

How to configure your nixvim input (and other channels) depends on how you have it installed:

You must use a nixpkgs version compatible with the nixvim version you choose.

The master branch requires to use a very recent version of nixpkgs unstable. In order to guarantee the compatibility between nixvim & nixpkgs it is recommended to always update both at the same time.

When using a stable version you must use the corresponding nixvim branch, for example nixos-24.05 when using NixOS 24.05.

Failure to use the correct branch, or an old revision of nixpkgs will likely result in errors of the form vimPlugins.<name> attribute not found.

The Installation Guide goes over most ways you can install nixvim.

malik-n commented 2 months ago

@MattSturgeon faq actually saved me. Had to switch to the 24.05 Branch on NixVim for it to work

yukkop commented 1 month ago

I having this on latest unstable (both with .follows and like below)

error:

error:
       … while calling the 'head' builtin

         at /nix/store/d6533m6b80n3c9lia5kvaz59ad3fynwk-source/lib/attrsets.nix:1575:11:

         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'

         at /nix/store/d6533m6b80n3c9lia5kvaz59ad3fynwk-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'cmp-ai' missing

       at /nix/store/p5bn87ks5k0a1w26vj8lfafafga733xg-source/plugins/completion/cmp/sources/_mk-cmp-plugin.nix:11:20:

           10|   sourceName,
           11|   defaultPackage ? pkgs.vimPlugins.${pluginName},
             |                    ^
           12|   maintainers ? [ lib.maintainers.GaetanLepage ],
       Did you mean one of cmp-dap, cmp-git or cmp-rg?

flake metadata:

└───nixvim: github:nix-community/nixvim/b7f419a759f70126e220533b724cc17e8528b184
    ├───devshell: github:numtide/devshell/67cce7359e4cd3c45296fb4aaf6a19e2a9c757ae
    │   └───nixpkgs follows input 'nixvim/nixpkgs'
    ├───flake-compat: https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz?narHash=sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U%3D
    ├───flake-parts: github:hercules-ci/flake-parts/8471fe90ad337a8074e957b69ca4d0089218391d
    │   └───nixpkgs-lib follows input 'nixvim/nixpkgs'
    ├───git-hooks: github:cachix/git-hooks.nix/bfef0ada09e2c8ac55bbcd0831bd0c9d42e651ba
    │   ├───flake-compat follows input 'nixvim/flake-compat'
    │   ├───gitignore: github:hercules-ci/gitignore.nix/637db329424fd7e46cf4185293b9cc8c88c95394
    │   │   └───nixpkgs follows input 'nixvim/git-hooks/nixpkgs'
    │   ├───nixpkgs follows input 'nixvim/nixpkgs'
    │   └───nixpkgs-stable follows input 'nixvim/nixpkgs'
    ├───home-manager: github:nix-community/home-manager/2598861031b78aadb4da7269df7ca9ddfc3e1671
    │   └───nixpkgs follows input 'nixvim/nixpkgs'
    ├───nix-darwin: github:lnl7/nix-darwin/076b9a905af8a52b866c8db068d6da475839d97b
    │   └───nixpkgs follows input 'nixvim/nixpkgs'
    ├───nixpkgs: github:NixOS/nixpkgs/8a3354191c0d7144db9756a74755672387b702ba
    ├───nuschtosSearch: github:NuschtOS/search/a05d1805f2a2bc47d230e5e92aecbf69f784f3d0
    │   ├───flake-utils: github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a
    │   │   └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
    │   └───nixpkgs follows input 'nixvim/nixpkgs'
    └───treefmt-nix: github:numtide/treefmt-nix/1d07739554fdc4f8481068f1b11d6ab4c1a4167a
        └───nixpkgs follows input 'nixvim/nixpkgs'

flake inputs:

  inputs = {
    ...
    nixvim = {
      url = "github:nix-community/nixvim";
    };
    ...
  }
MattSturgeon commented 1 month ago

@yukkop if you're using one of the NixOS/home-manager/Darwin modules, then the flake input follows isn't very relevant.

Instead, what matters is the "host" module's pkgs module arg. If your host modules are using (e.g.) 24.05 for pkgs, then nixvim's modules will too.

If you want to use unstable nixvim on a stable host, the only way to (currently) achieve this is with a standalone build.

In the future #1784 will provide another solution to this problem.