The repository contains nix flake to install the NvChad
configuration on any system that uses Nix and nix flakes.
- nvchad package
- home-manager module
You can choose any of the presented methods to install NvChad.
General notes
NvChad itself is not an executable file, it is a perfect configuration for [Neovim](https://neovim.io/).
Unfortunately there is no easy way to add it to /nix/store
More precisely, it’s easy to add it, but it won’t work, at least for now (version 2.5)
This is due to the fact that by default neovim reads
the file ~/.config/nvim/init.lua and starts.
NvChad lazily loads plugins and on first load, lazyvim will save
lazy-lock.json next to ~/.config/nvim/init.lua
As you understand, this is not a problem for any distribution and it
does not violate the principles of The Twelve Factor App
because, as already said, NvChad is a configuration and not a package with an application.
But with Nix the problem is /nix/store is a read-only system,
the source code trying to write a file or change the current one will result in an error.
There will also be a problem with the ability to change the configuration
on the fly, since this changes the chadrc.lua file
The method We used to solve this problem (home-manager module) is a hack.
Don't worry, it doesn't break anything, but it doesn't follow the basic
principle of how home-manager adds configuration files to the user's home directory.
Absolutely all configuration files are stored in /nix/store/
By default, the home manager creates symbolic links from /nix/store/ to the user's home directory.
This ensures that configuration changes after the next generation build are available to the user.
In addition, if you have ever created a declarative configuration
for vanilla neovim you know that plugins are also stored in /nix/store/
NvChad installs plugins in ~/.local/share/nvim/.
This is not a problem for us, they are still immutable until you explicitly update them.
If your own NvChad configuration which you pass
to the module as config.programs.nvchad.extraConfig
contains lazy-lock.json specific plugin versions will be installed.
Here's everything you need to know before you start using NvChad with Nix If you still need to add NvChad to your configuration, welcome!
- you add this repository as inputsto flake.nix of your configuration
- you add a package with NvChadto your configuration as an overlay or as ahome-managermodule
- specify extraPackages and extraConfig for the package or module
- you are building a new system generation
- as a result, you will receive an executable file nvim, nvim.desktop to launch from the launcher and your own configuration overlay if you passed extraConfig
- each extraPackages is available to NvChad, if this is for example an LSP server, NvChad will find its executable file
- extraPackages are not available globally, they are only available in the NvChad scope
- if you do not pass any parameters only extraPackagesfor starter configuration are included
nix run github:nix-community/nix4nvchad/#nvchadWarning
Run the command above if you are not using your neovim configuration!
- If you already have a neovimconfiguration in~/.config/nvimandinit.luais present there nvchad will not copy the configuration to the home directory and will probably not start correctly
- If there is no init.luain~/.config/nvimbut there are any other files, this will overwrite~/.config/nvimwith theNvChad starterconfiguration
- Your current configuration will be saved in ~/.config/nvim/nvim_%Y_%m_%d_%H_%M_%S.bak
To install it you must have flake enabled and your NixOS configuration must be managed with flakes. See Flakes for instructions on how to install and enable them on NixOS.
You can add this flake as inputs in flake.nix in the repository
containing your NixOS configuration:
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    # ...
    nix4nvchad = {
      url = "github:nix-community/nix4nvchad";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    # ...
  };This flake provides an overlay for Nixpkgs, with package and a home-manager module.
They are respectively found in the flake as
- 
inputs.nix4nvchad.packages.${system}.default
- 
inputs.nix4nvchad.packages.${system}.nvchad
- 
inputs.nix4nvchad.homeManagerModules.default
- 
inputs.nix4nvchad.homeManagerModules.nvchad
- 
inputs.nix4nvchad.homeManagerModule
(Where ${system} is either x86_64-linux aarch64-linux x86_64-darwin aarch64-darwin)
Output data can be added in different ways, for example this is how I do it for NixOS:
In the example below, the home manager is installed as a NixOS module
  outputs = { self, nixpkgs, home-manager, ... }@inputs:
    let
      system = "x86_64-linux";
      lib = nixpkgs.lib;
      extraSpecialArgs = { inherit system inputs; };  # <- passing inputs to the attribute set for home-manager
      specialArgs = { inherit system inputs; };       # <- passing inputs to the attribute set for NixOS (optional)
    in {
    nixosConfigurations = {
      dummy-host = lib.nixosSystem {
        modules = [
          inherit specialArgs;           # <- this will make inputs available anywhere in the NixOS configuration
          ./path/to/configuration.nix
          home-manager.nixosModules.home-manager {
            home-manager = {
              inherit extraSpecialArgs;  # <- this will make inputs available anywhere in the HM configuration
              useGlobalPkgs = true;
              useUserPackages = true;
              users.dummyUserName = import ./path/to/home.nix;
            };
          }
        ];
      };
    };
  };If you are new to NixOS here is a useful channel Vimjoyer
All we have to do is add nvchad to the list of available packages using overlays
Somewhere in your configuration.nix
{ config, pkgs, inputs, ... }: {  # <-- inputs from flake
  # ...
  nixpkgs = { 
    overlays = [
      (final: prev: {
        nvchad = inputs.nix4nvchad.packages."${pkgs.system}".nvchad;
      })
    ];
  };
  # ...
}Now you can call the package anywhere as a package from nixpkgs
- pkgs.nvchad
Examples:
- users.users.<name>.packages = [ pkgs.nvchad ];NixOS
- home.packages = with pkgs; [ pkgs.nvchad ];home-manager
Depending on which usage method you choose, take a look at a couple of snippets:
Somewhere in your home.nix or a separate module:
Default:
{ inputs, config, pkgs, ... }: {
  imports = [
    inputs.nix4nvchad.homeManagerModule
  ];
  programs.nvchad.enable = true;
}Or with customization of options:
{ inputs, config, pkgs, ... }: {
  imports = [
    inputs.nix4nvchad.homeManagerModule
  ];
  programs.nvchad = {
    enable = true;
    extraPackages = with pkgs; [
      nodePackages.bash-language-server
      docker-compose-language-service
      dockerfile-language-server-nodejs
      emmet-language-server
      nixd
      (python3.withPackages(ps: with ps; [
        python-lsp-server
        flake8
      ]))
    ];
    hm-activation = true;
    backup = true;
  };
}All options are not required
true or false
If false ignore this module when build new generation
pkgs.neovim
Neovim package for use under nvchad wrapper
return {
  {"equalsraf/neovim-gui-shim",lazy=false},
  {"lervag/vimtex",lazy=false},
  {"nvim-lua/plenary.nvim"},
  {
    'xeluxee/competitest.nvim',
    dependencies = 'MunifTanjim/nui.nvim',
    config = function() require('competitest').setup() end,
  },
}The extra plugins you want to install. Loaded by lazy.nvim
[] list of pkgs
List of additional packages available for NvChad as runtime dependencies NvChad extensions assume that the libraries it need will be available globally. By default, all dependencies for the starting configuration are included. Overriding the option will expand this list.
string
The config written in lua. It will be loaded after nvchad loaded.
string
Configuration that replaces chadrc.lua. Make sure to include local M = {} at the top, and return M at the bottom.
pkg.gcc
The gcc compiler you want to use.
string
A json file. Which is in ~/.config/nvim/lazy-lock.json to lock lazy.nvim's plugin.
Leave it as "" if don't want it.
true or false
It's a trick If you do not want home-manager to manage nvchad configuration, set the false option. In this case, HM will not copy the configuration saved in /nix/store to ~/.config/nvim. This way you can customize the configuration in the usual way by cloning it from the NvChad repository. By default, the ~/.config/nvim is managed by HM.
true or false
Since the module violates the principle of immutability
and copies NvChad to ~/.config/nvim rather than creating
a symbolic link by default, it will create a backup copy of
~/.config/nvim_%Y_%m_%d_%H_%M_%S.bak when each generation.
This ensures that the module
will not delete the configuration accidentally.
You probably do not need backups, just disable them
config.programs.nvchad.backup = false;
Whichever method you choose, after installation you'll probably want to run NvChad.
Using the nvim wrapper executable it will be automatically available in your $PATH.
You can also launch through the application manager (rofi, wofi, etc).
The package comes with nvim.desktop.
If you are not using the HM module or have disabled hm-activation:
- NvChadexpects- ~/.config/nvim/init.luato be available at startup
- if the file does not exist, NvChadwill copy it and all files from/nix/store/hash-nvchad-2.5/config
- this will be either your configuration or starter
- if ~/.config/nvim/is not emptyNvChadwill create a backup copy nearby
If you are using the NvChad home-manager module, do not add neovim from the standard module:
programs.neovim.enable = true;Also, do not add neovim as a package to the configuration:
home.packages = [ pkgs.neovim ];You can use your own NvChad configuration by providing your own repository or local folder.
It has to follow the structure of the NvChad starter (a fork or local copy).
  inputs = {
    # Default:
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    # adding the starter input here
    nvchad-starter = {
      url = "github.com:<github-username>/<repository-name>"; # <- replace this with your own
      # url = "path:<local_path>" # <- for local relative folder (e.g. path:./home/nvim) 
      flake = false;
    }
    nix4nvchad = {
      url = "github:nix-community/nix4nvchad";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.nvchad-starter.follows = "nvchad-starter"; # <- overwrite the module input here
    };
  };And follow above steps.
