Git Product home page Git Product logo

nix-neovim's Introduction

nix-neovim

The goal of this project is to have a NixOS- and home-manager-like way to manage my neovim installation. I will add stuff I use but it is completely extendible by everyone! You can split up your configuration into modules because I'm piggybacking off the NixOS module system.

The output of running :checkhealth.

Usage

This project gives you the function buildNeovim that takes a configuration and pkgs. Available options for configuration can be found by running :help nix-neovim-configuration.txt inside of a neovim instance produced by nix-neovim. A very basic example configuration goes as follows:

# config.nix
{ pkgs, ... }:

{
  # imports = [ <your other modules here> ];

  vim = {
    keybindings = {
      leader = " ";
      which-key-nvim = true;

      keybindings-shortened = {
        "<leader>;" = {
          command = "<Plug>NERDCommenterToggle";
          options.silent = true;
        };
      };
    };

    g.tokyonight_style = "storm";
    opt.showmode = false;
  };

  output = {
    path.style = "pure";
    plugins = with pkgs.vimPlugins; [
      nerdcommenter
      vim-nix
      tokyonight-nvim
    ];
    extraConfig = ''
      colorscheme tokyonight
    '';
  };
}

# flake.nix
{
  inputs = { nix-neovim.url = "github:syberant/nix-neovim"; };

  outputs = { self, nix-neovim }: {
    # For nix build
    defaultPackage."x86_64-linux" = nix-neovim.buildNeovim {
      configuration = ./config.nix;
      # pkgs = <your own instance of nixpkgs here>;
    };

    # For nix run
    defaultApp."x86_64-linux" = {
      type = "app";
      program = "${self.defaultPackage."x86_64-linux"}/bin/nvim";
    };
  };
}

Now you can try it out with nix run .#!

You could also try out some premade configs:

$ # Try out the example (./test.nix) configuration
$ nix run github:syberant/nix-neovim
$ # Or my personal configuration (warning: it has LARGE dependencies, LaTeX in particular.)
$ nix run github:syberant/nix-config#neovim

Philosophy

Early on this project contained default configurations for many common plugins, each with relevant options. This caused a great deal of pain as there was little distinction between nix-neovim and my personal neovim config and constantly updating these options turned out to be very opinionated and problematic (trying to get them complete even more so). If extensive and elaborate options appeal to you go check out some of the other projects in the Links section!

My current goal for this project is to explicitly exclude configuration of specific plugins and instead only provide tools for managing neovim configuration with Nix. This results in features like:

  • vim.opt to set options (set KEY=VALUE in vimscript)
  • vim.g to set global variables (let g:KEY=VALUE in vimscript)
  • vim.keybindings to set keymappings (a hot mess in vimscript)
  • Purity modes
  • plugin.setup to handle the common pattern require(KEY).setup(VALUE) of lua plugins

Many of these features are accomplished by allowing users to define a Nix set and then generating an equivalent JSON file, lua code then reads that JSON file and does the appropriate configuration. This allows splitting up your configuration into many small modules as these Nix sets are merged together like you expect.

Debugging

nix-neovim provides some tools for helping you debug your neovim config:

  • :help nix-neovim-configuration.txt contains a complete list of options, similar to man configuration.nix for NixOS
  • :checkhealth nix_neovim for a quick overview of your configuration
  • :NixNeovimRc opens your generated vimrc
  • :NixNeovimPlugins opens the directory of your installed plugins
  • Switching between purity modes (see :h output.path.style) can be done live:
    • :NixNeovimPathPure sets $PATH to only contain packages defined in output.path.path
    • :NixNeovimPathImpure prefixes $PATH with packages defined in output.path.path
    • :NixNeovimPathNopath resets $PATH to your own environment

Links

nix-neovim's People

Contributors

syberant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

dundargoc

nix-neovim's Issues

How to replace `nvim` with `nix-config` built one?

I really like this project mainly due to how it doesn't try to implement every plugin as a module I feel I have more control that way.
I would like to try replace nvim with mine from nvim.buildNeovim. I have tried using overlays but without much luck mainly due to me not knowing nix well enough.
Both HM module nixpkgs.overlays and overlays.default

            ({ pkgs, ...}: {
              nixpkgs.overlays = [
                (final: prev: {
                  nvim = args.nix-neovim.buildNeovim {
                    configuration = ./nix/home-manager/nvim/configuration.nix;
                  };
                })
              ];
            })

doesn't seem to do anything can you please help me?

Unable to make LSP packages available in PATH

Hi, I don't know how to make anything available for neovim in PATH this is the only way how I managed to not get error about bash-language-server not available in PATH when opening .sh file.

{ pkgs, ... }: {
  output.plugins = with pkgs.vimPlugins; [ nvim-lspconfig ];

  output.config_file = ''
    lua <<EOF
      local on_attach = function(client, bufnr)
        local bufopts = { noremap=true, silent=true, buffer=bufnr }
        vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
      end

      require('lspconfig')['bashls'].setup {
        on_attach = on_attach,
        cmd = {"${pkgs.nodePackages.bash-language-server}/bin/bash-language-server"},
      }
    EOF
  '';
}

but just this should work no?

{ pkgs, ... }: {
  output.plugins = with pkgs.vimPlugins; [ nvim-lspconfig ];

  output.path.path = with pkgs; [
    nodePackages.bash-language-server
  ];

  output.config_file = ''
    lua <<EOF
      require('lspconfig')['bashls'].setup {}
    EOF
  '';
}

I tried both impure and pure for output.path.style but the error stays the same. Could you please help me?

Edit:

Checking the nix-neovim-PATH and everything seems ok bash -> /nix/store/wim4mqpn8lxhhr10p2kd070hyj152lil-bash-5.1-p16/bin/bash I'll try other languages maybe there's something specific about bash I am not getting.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.