nix-community / nixvim

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

[BUG] Can't use nixvim inside a flake because of `error: attribute 'base16-nvim' missing` #1330

Closed ElrohirGT closed 3 months ago

ElrohirGT commented 3 months ago
Field Description
Plugin none
Nixpkgs unstable
Home Manager none

Description

I'm trying to have a simple neovim config to test an LSP I'm developing, ideally I would like to run: nix run .#vim and that should generate a neovim config with my LSP configured to it. But even though I added nixvim to my flake inputs it doesn't build and fails with:

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nixvim'
         whose name attribute is located at /nix/store/bn7d9rhgmmz0l4x9ykv5q10gzq1rkxci-source/pkgs/stdenv/generic/make-derivation.nix:348:7

       … while evaluating attribute 'paths' of derivation 'nixvim'

         at /nix/store/yd5x5j3kxjv99l0v6r86ch4lqzsl3qb2-source/wrappers/standalone.nix:46:7:

           45|       name = "nixvim";
           46|       paths =
             |       ^
           47|         [

       error: attribute 'base16-nvim' missing

       at /nix/store/yd5x5j3kxjv99l0v6r86ch4lqzsl3qb2-source/plugins/colorschemes/base16/default.nix:15:22:

           14|     originalName = "base16.nvim";
           15|     defaultPackage = pkgs.vimPlugins.base16-nvim;
             |                      ^
           16|
       Did you mean base16-vim?

Minimal, Reproducible Example (MRE)

{
  description = "Mermaid LSP flake";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-23.11";
    systems.url = "github:nix-systems/default";
    rust-overlay.url = "github:oxalica/rust-overlay";
    devenv = {
      url = "github:cachix/devenv";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixvim = {
      # If you are not running an unstable channel of nixpkgs,
      # select the corresponding branch of nixvim.
      # url = "github:nix-community/nixvim/nixos-23.05";
      url = "github:nix-community/nixvim";

      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  nixConfig = {
    extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
    extra-substituters = "https://devenv.cachix.org";
  };

  outputs = {
    self,
    nixpkgs,
    systems,
    rust-overlay,
    devenv,
    nixvim,
    ...
  } @ inputs: let
    overlays = [(import rust-overlay)];
    forEachSystem = nixpkgs.lib.genAttrs (import systems);
  in {
    packages = forEachSystem (system: let
      pkgs = import nixpkgs {inherit system overlays;};
      rustVersion = pkgs.rust-bin.stable.latest.default;
      rustPlatform = pkgs.makeRustPlatform {
        cargo = rustVersion;
        rustc = rustVersion;
      };
    in {
      # For setting up devenv
      devenv-up = self.devShells.${system}.default.config.procfileScript;

      vim = nixvim.legacyPackages.${system}.makeNixvim {};

      nvim = nixvim.legacyPackages.${system}.makeNixvim {
        colorschemes.gruvbox.enable = true;
        extraConfigLua = ''
          # TODO: Add extra config of vim here!
          local client = vim.lsp.start_client {
            name = "mermaid_lsp",
            cmd = {"path to my lsp"}
          }

          if not client then
            vim.notify "Hey! You did an upsie configuring the client for the LSP!"
            return
          end

          vim.api.nvim_create_autocmd("FileType", {
            pattern = "markdown",
            callback = function()
                vim.lsp.buf_attach_client(0, client)
            end
          })
        '';
      };
    });

    devShells = forEachSystem (system: let
      pkgs = import nixpkgs {inherit system overlays;};
    in {
      default = devenv.lib.mkShell {
        inherit pkgs inputs;
        modules = [
          {
            packages = with pkgs; [
              # Latest stable release
              (rust-bin.stable.latest.default)
            ];
          }
        ];
      };
    });
  };
}

Any help would be greatly appreciated!

ElrohirGT commented 3 months ago

My bad! I didn' notice nixpkgs was targeting 23.11 instead of unstable!

ElrohirGT commented 3 months ago

Ok so I've deleted the flake.lock and changed the MRE to this:

{
  description = "Mermaid LSP flake";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/unstable";
    systems.url = "github:nix-systems/default";
    rust-overlay.url = "github:oxalica/rust-overlay";
    devenv = {
      url = "github:cachix/devenv";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixvim = {
      # If you are not running an unstable channel of nixpkgs,
      # select the corresponding branch of nixvim.
      # url = "github:nix-community/nixvim/nixos-23.05";
      url = "github:nix-community/nixvim";

      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  nixConfig = {
    extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
    extra-substituters = "https://devenv.cachix.org";
  };

  outputs = {
    self,
    nixpkgs,
    systems,
    rust-overlay,
    devenv,
    nixvim,
    ...
  } @ inputs: let
    overlays = [(import rust-overlay)];
    forEachSystem = nixpkgs.lib.genAttrs (import systems);
  in {
    packages = forEachSystem (system: let
      pkgs = import nixpkgs {inherit system overlays;};
      rustVersion = pkgs.rust-bin.stable.latest.default;
      rustPlatform = pkgs.makeRustPlatform {
        cargo = rustVersion;
        rustc = rustVersion;
      };
    in {
      # For setting up devenv
      devenv-up = self.devShells.${system}.default.config.procfileScript;

      vim = nixvim.legacyPackages.${system}.makeNixvim {};

      nvim = nixvim.legacyPackages.${system}.makeNixvim {
        colorschemes.gruvbox.enable = true;
        extraConfigLua = ''
          # TODO: Add extra config of vim here!
          local client = vim.lsp.start_client {
            name = "mermaid_lsp",
            cmd = {"path to my lsp"}
          }

          if not client then
            vim.notify "Hey! You did an upsie configuring the client for the LSP!"
            return
          end

          vim.api.nvim_create_autocmd("FileType", {
            pattern = "markdown",
            callback = function()
                vim.lsp.buf_attach_client(0, client)
            end
          })
        '';
      };
    });

    devShells = forEachSystem (system: let
      pkgs = import nixpkgs {inherit system overlays;};
    in {
      default = devenv.lib.mkShell {
        inherit pkgs inputs;
        modules = [
          {
            packages = with pkgs; [
              # Latest stable release
              (rust-bin.stable.latest.default)
            ];
          }
        ];
      };
    });
  };
}

But it still gives the same error!

ElrohirGT commented 3 months ago

Turns out I didn't check the correct file before so the MRE failed the same. The fix was to just make nixpkgs follow unstable as my previous comment denied incorrectly. Sorry to bug you all with my skill issue

GaetanLepage commented 3 months ago

No worry ! Glad you fixed it :)