Home Manager with nixvim issue

How to Properly Integrate NixVim with Home Manager?

I’ve been facing challenges integrating NixVim with Home Manager in my home.nix configuration. I’m using a Nix flake-based setup, and I’m unsure if my integration approach is correct.

Here’s my flake.nix file:

{
  description = "NixOS - Declarative and user-friendly NixOS configuration with Home Manager and NixVim";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.05";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixvim = {
      url = "github:dc-tec/nixvim";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    polymc = {
      url = "github:PolyMC/PolyMC";
    };
  };
  outputs = { self, ... }@inputs:
    let
      lib = inputs.nixpkgs.lib;
      system = "x86_64-linux";
      pkgs = inputs.nixpkgs.legacyPackages.${system};
      pkgs-stable = inputs.nixpkgs.legacyPackages.${system};
      userSettings = {
        username = "miskat";
        hostname = "nixos";
        email = "miskatul.anwar.csecu@gmail.com";
        editor = "nvim";
      };
    in {
      nixosConfigurations = {
        ${userSettings.hostname} = lib.nixosSystem {
          inherit system;
          modules = [ ./nixos/configuration.nix ];
          specialArgs = {
            inherit inputs userSettings pkgs-stable;
          };
        };
      };
      homeConfigurations = {
        ${userSettings.username} = inputs.home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [ ./home-manager/home.nix ];
          extraSpecialArgs = {
            inherit inputs userSettings pkgs-stable;
          };
        };
      };
    };
}

And here’s my home.nix file:

{ config, inputs, pkgs, pkgs-stable, userSettings, ... }:
{
  imports = [
    ./modules/bundle.nix
    inputs.nixvim.nixosModules
  ];
  home.username = userSettings.username;
  home.homeDirectory = "/home/" + userSettings.username;
  programs.neovim.defaultEditor = true;
  home.stateVersion = "24.05";
  programs.nixvim = {
    enable = true;
  };
  home.packages = [
    pkgs.hello
    pkgs.alacritty
    (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; })
  ];
  home.file = {
    ".zshrc".text = ''
      alias "ls"="lsd"
      # other aliases...
    '';
    # Additional file sources...
  };
  home.sessionVariables = {
    EDITOR = userSettings.editor;
    CC = "clang";
    CXX = "clang++";
  };
  programs.home-manager.enable = true;
}

The Issue

When I run home-manager switch --flake ~/.nix#miskat, I get the following error:

error:
       … while evaluating a branch condition
       … while calling the 'length' builtin
       error: attribute 'default' missing

I suspect the issue is related to how I reference NixVim in home.nix. Specifically, I’m unsure whether inputs.nixvim.nixosModules is the correct way to import NixVim into my configuration.

Questions

  1. Is my flake.nix and home.nix setup for NixVim correct?
  2. How should I reference NixVim in home.nix to properly enable it?
  3. Could the issue stem from missing or misconfigured imports for NixVim?

—home-manager switch --flake ~/.nix#miskat
error:
… while evaluating a branch condition
at /nix/store/frfyxcpzsdasdin76x83krbhpgkis8b0-source/lib/lists.nix:125:9:
124| fold’ = n:
125| if n == len
| ^
126| then nul

   … while calling the 'length' builtin
     at /nix/store/frfyxcpzsdasdin76x83krbhpgkis8b0-source/lib/lists.nix:123:13:
      122|     let
      123|       len = length list;
         |             ^
      124|       fold' = n:

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

   error: The option `inputs' does not exist. Definition values:
   - In `/nix/store/6jycrpdgq43vma9zrcvwipp864spbbvi-source/home-manager/home.nix':
       {
         nixvim = {
           enable = true;
           settings = {
             plugins = [
       ...

Let me know if this needs further refinement!

Update: Resolved Issue with NixVim Integration

I’ve successfully resolved the issue with integrating NixVim into my home.nix configuration. Here’s the corrected setup:

Key Changes:

  1. NixVim Module Source:
    Instead of using inputs.nixvim.nixosModules, I switched to inputs.nixvim.homeManagerModules.nixvim, which correctly integrates NixVim with Home Manager.

  2. Flake Setup:
    I updated the flake.nix configuration to properly fetch NixVim from the correct URL (github:nix-community/nixvim). I also ensured proper integration of the unstable and stable Nixpkgs channels and Home Manager.

Configuration:

{ config, inputs, pkgs, pkgs-stable, userSettings, ... }:
{
  imports = [
    ./modules/bundle.nix
    # inputs.nixvim.nixosModules
    inputs.nixvim.homeManagerModules.nixvim
  ];

  home.username = userSettings.username;
  home.homeDirectory = "/home/" + userSettings.username;
  programs.neovim.defaultEditor = true;
  home.stateVersion = "24.05";

  programs.nixvim = {
    enable = true;
    colorschemes.oxocarbon.enable = true;
  };

  home.packages = [
    pkgs.hello
    pkgs.alacritty
    (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; })
  ];

  home.file = {
    ".zshrc".text = ''
      alias "ls"="lsd"
      alias "cd"="z"
      # Add other alias definitions here
      neofetch
    '';
    # ".config/nvim".source = modules/nvim;
    ".ssh".source = modules/sshkeys;
    ".gdbinit".source = modules/gdb/.gdbinit;
    # Additional files
  };

  home.sessionVariables = {
    EDITOR = userSettings.editor;
    CC = "clang";
    CXX = "clang++";
  };

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
}

Flake Configuration:

{
  description = "Chad NixOS - Declarative and user-friendly NixOS configuration with Home Manager and NixVim";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.05";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixvim = {
      url = "github:nix-community/nixvim";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    polymc = {
      url = "github:PolyMC/PolyMC";
    };
  };
  outputs = { self, ... }@inputs:
    let
      lib = inputs.nixpkgs.lib;
      system = "x86_64-linux";
      pkgs = inputs.nixpkgs.legacyPackages.${system};
      pkgs-stable = inputs.nixpkgs.legacyPackages.${system};
      userSettings = {
        username = "miskat";
        hostname = "nixos";
        email = "miskatul.anwar.csecu@gmail.com";
        editor = "nvim";
      };
    in
    {
      nixosConfigurations = {
        ${userSettings.hostname} = lib.nixosSystem {
          inherit system;
          modules = [ ./nixos/configuration.nix ];
          specialArgs = { inherit inputs userSettings pkgs-stable; };
        };
      };
      homeConfigurations = {
        ${userSettings.username} = inputs.home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [ ./home-manager/home.nix ];
          extraSpecialArgs = { inherit inputs userSettings pkgs-stable; };
        };
      };
    };
}

Key Points:

  • Replaced inputs.nixvim.nixosModules with inputs.nixvim.homeManagerModules.nixvim for correct module loading.
  • Integrated NixVim with Home Manager and added a color scheme (oxocarbon).
  • Ensured Home Manager’s self-management by enabling programs.home-manager.

This configuration is working as expected now. If anyone faces similar issues, I hope this solution helps!
I’ve imported my plugins .nix files and they also work correctly.