Declarative Nvchad installation on nixos

Hello, I’m recently try out nixos and I’m quite used to using nvim with nvchad. I have home-manager and tried out the following config to install nvchad plugin for neovim:

# in home.nix
  programs.neovim = {
    enable = true;
    defaultEditor = true;
    plugins = with pkgs.vimPlugins; [
      #nvim-tree-lua
      nvim-treesitter
      elixir-tools-nvim
      nvchad-ui
      catppuccin-nvim
    ];
  };

however, when I open nvim, there’s some error:

Error detected while processing /nix/store/yd24wn6dyprh6s1aq58fv363f3ag2zyj-vimplugin-nvchad-ui-2023-10-30/plug
in/init.lua:
E5113: Error while calling lua chunk: ...ack/myNeovimPackages/start/nvchad-ui/lua/nvchad/init.lua:2: module 'co
re.utils' not found:
        no field package.preload['core.utils']
        no file '/nix/store/fil9z2hnrak3b37fj4n0ki2n0n3fwrni-luajit-2.1.1693350652-env/share/lua/5.1/core/utils
.lua'
        no file '/nix/store/fil9z2hnrak3b37fj4n0ki2n0n3fwrni-luajit-2.1.1693350652-env/share/lua/5.1/core/utils
/init.lua'
        no file '/nix/store/fil9z2hnrak3b37fj4n0ki2n0n3fwrni-luajit-2.1.1693350652-env/lib/lua/5.1/core/utils.s
o'
        no file '/nix/store/fil9z2hnrak3b37fj4n0ki2n0n3fwrni-luajit-2.1.1693350652-env/lib/lua/5.1/core.so'
stack traceback:
        [C]: in function 'require'
        ...ack/myNeovimPackages/start/nvchad-ui/lua/nvchad/init.lua:2: in main chunk
        [C]: in function 'require'
        ...3f3ag2zyj-vimplugin-nvchad-ui-2023-10-30/plugin/init.lua:1: in main chunk

I’m not at all familiar with lua and how nvchad works. Can someone help me? Thank you!

1 Like

found the solution:
below is my file hierarchy in /etc/nixos/:

.
├── configuration.nix
├── configuration.nix.BACKUP
├── hardware-configuration.nix
├── home.nix
├── nvchad
    ├─ custom
    └─ default.nix

in ./nvchad/default.nix:

{ stdenv, pkgs, fetchFromGithub }:

{
nvchad = stdenv.mkDerivation rec {
  pname = "nvchad";
  version = "";
  dontBuild = true;

  src = pkgs.fetchFromGitHub {
    owner = "NvChad";
    repo = "NvChad";
    rev = "c8777040fbda6a656f149877b796d120085cd918";
    sha256 = "sha256-J4SGwo/XkKFXvq+Va1EEBm8YOQwIPPGWH3JqCGpFnxY=";
  };

  installPhase = ''
    # Fetch the whole repo and put it in $out
    mkdir $out
    cp -aR $src/* $out/
  '';
  };
}

in home.nix:

  # basically copy the whole nvchad that is fetched from github to ~/.config/nvim
  xdg.configFile."nvim/" = {
    source = (pkgs.callPackage ./nvchad/default.nix{}).nvchad;
  };

and that just works miraculously

2 Likes

hi,

i’m relatively new to NixOS and i haven’t managed to wrap the concept of home-manager and etc around my head. i tried the process you described but i have several questions:

  • do you still need to install the plugins manually?
  • what’s the custom file/folder? what’s the purpose?

cheers

i really dont have any idea what i did actually, i just copy what ray-andrew did in this reddit post