Nixvim infinite recursion issue

Hello,

Having a tough time with integrating Nixvim in to my setup. I removed all references to Neovim from configuration and home.nix. I have gone through every iteration or combination that I have found online regarding this issue, but still am not able to resolve it.

This other post is similar to what I’m experiencing but moving the import in to the home.nix did not resolve the issue for me. Cannot get nixvim to install as a module in home-manager

I’ve tried;

  • Inherit nixvim in special args and extra args.
  • Import module in flake, Home Manager and NixOS, both same infrec error

Here is my current testing flake.nix;

{
  inputs = {

    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

    home-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";

    nixvim.url = "github:nix-community/nixvim";
    nixvim.inputs.nixpkgs.follows = "nixpkgs";

    hyprland.url = "github:hyprwm/Hyprland";
    
   
  };

  outputs = inputs@{
    nixpkgs,
    home-manager,
    nixvim,
    hyprland,
    ...
  }:

  let

    system = "x86_64-linux";

    homeManager = {
         mod = ./modules;
         df = ./modules/dotfiles;
         cfg = ./modules/dotfiles/config;
    };

  in

  {
    # NixOS configuration entrypoint
    nixosConfigurations = {
      tbnix = nixpkgs.lib.nixosSystem {
        specialArgs = { 
          inherit system; inherit inputs; inherit nixvim;
        };
        modules = [
          ./hosts/tbnix
	  # nixvim.nixosModules.nixvim
	  # nixvim.homeManagerModules.nixvim
          home-manager.nixosModules.home-manager {
            home-manager.extraSpecialArgs = { inherit homeManager; inherit nixvim; };
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.fez = {
	      imports = [ ./hosts/tbnix/home.nix nixvim.homeManagerModules.nixvim];
	      };
          }
...

TB Laptop/workstation home.nix which imports the common home.nix. Tried importing nixvim here. Still had infrec issue.

{ inputs, config, lib, pkgs, modulesPath, homeManager, ... }:

{
  imports = [
    ../common/home.nix
    # inputs.nixvim.homeManagerModules.nixvim 
  ];

  home.file = {
    ".config/hypr/common.conf" = {
      source = homeManager.cfg + /hypr/common.conf;
    };
    ".config/hypr/keybind" = {
      source = homeManager.cfg + /hypr/keybind;
    };
    ".config/rofi/" = {
      source = homeManager.cfg + /rofi;
    };
    ".config/waybar/" = {
      source = homeManager.cfg + /waybar;
    };
    ".config/hypr/autostart.conf" = {
      source = homeManager.cfg + /hypr/autostart.conf;
    };
    ".config/hypr/hyprpaper.sh" = {
      source = homeManager.cfg + /hypr/hyprpaper.sh;
      executable = true;
    };
    ".config/hypr/hyprlock.txt" = {
      source = homeManager.cfg + /hypr/hyprlock.txt;
    };
    ".config/hypr/hyprlock.sh" = {
      source = homeManager.cfg + /hypr/hyprlock.sh;
      executable = true;
    };
    ## TODO these lines need to be changed per device
    ".config/hypr/hyprland.conf" = {
      source = homeManager.cfg + /tbhypr/hyprland.conf;
    };
    # ".config/hypr/hyprpaper.conf" = {
    #   source = homeManager.cfg + ./tbhypr/hyprpaper.conf;
    # };
    ".config/hypr/hypridle.conf" = {
      source = homeManager.cfg + /tbhypr/hypridle.conf;
    };
  };
}

This is the common home.nix. Tested a few variaties of Nix Kikstart Neovim but decided to remove any imports and I’m just running programs.nixvim.enable = true; for now with no other options.

{ inputs, config, lib, pkgs, modulesPath, homeManager, ... }:

{
  imports = [

    inputs.nixvim.homeManagerModules.nixvim 
    (homeManager.df + "/tmux.nix")
    (homeManager.df + "/lf.nix")
    (homeManager.df + "/zsh.nix")
    (homeManager.df + "/vscode.nix")
    # (homeManager.mod + "/nixvim/nixvimkiktst.nix")
    # (homeManager.mod + "/nixvim/nixvimkik.nix")
    # (homeManager.mod + "/nixvim/neovim.nix")
    # (homeManager.mod + "/nixvim/neovimlsp.nix")
  ];

  # Environment variables
  home.sessionVariables = {
    CARGO_HOME = "~/.local/share/cargo";
  };

  home = {
    username = "fez";
    homeDirectory = "/home/fez";
  };

  home.file = {
    ".scripts" = {
      source = homeManager.df + /scripts;
      executable = true;
      recursive = true;
    };
    ".vimrc" = {
      source = homeManager.df + /vimrc.txt;
      executable = true;
    };
    # launch keepassxc with hyprland
    # add window rules and launch binding
    ".config/hypr/keepassxc.conf".text = ''
      exec-once = keepassxc
      windowrulev2 = size 800 550, class:^(org.keepassxc.KeePassXC)$
      # windowrulev2 = float, class:^(org.keepassxc.KeePassXC)$
      windowrulev2 = bordercolor $cc, class:^(org.keepassxc.KeePassXC)$
      bind = $mainMod, z, exec, keepassxc
    '';
  };

  # PACKAGES
  home.packages = with pkgs; [
    zsh-command-time
    kdePackages.kate
    thunderbird
    brightnessctl
    pinta
    freecad-wayland
  ];

  programs.nixvim = {
    enable = true;
  };


  # Configure Kitty
  programs.kitty = {
    enable = true;

...

  home.stateVersion = "24.05";
}

Here is the error;

❯ nix flake check
warning: Git tree '/home/fez/gitgoml/nixos' is dirty
error:
       … while checking flake output 'nixosConfigurations'
         at /nix/store/n8zimmccccqh32dk7308y78f0g49cyic-source/flake.nix:84:5:
           83|     # NixOS configuration entrypoint
           84|     nixosConfigurations = {
             |     ^
           85|       tbnix = nixpkgs.lib.nixosSystem {

       … while checking the NixOS configuration 'nixosConfigurations.tbnix'
         at /nix/store/n8zimmccccqh32dk7308y78f0g49cyic-source/flake.nix:85:7:
           84|     nixosConfigurations = {
           85|       tbnix = nixpkgs.lib.nixosSystem {
             |       ^
           86|         specialArgs = {

       … while evaluating the option `system.build.toplevel':

       … while evaluating definitions from `/nix/store/22r7q7s9552gn1vpjigkbhfgcvhsrz68-source/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `assertions':

       … while evaluating definitions from `/nix/store/xi3dvmqv5mrj0281i9sl4hfpzkwq3cmz-source/nixos/common.nix':

       … while evaluating the module argument `inputs' in "/nix/store/n8zimmccccqh32dk7308y78f0g49cyic-source/hosts/tbnix/home.nix":

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

       error: infinite recursion encountered
       at /nix/store/22r7q7s9552gn1vpjigkbhfgcvhsrz68-source/lib/modules.nix:515:28:
          514|         addErrorContext (context name)
          515|           (args.${name} or config._module.args.${name})
             |                            ^
          516|       ) (functionArgs f);

Any help is much appreciated. Thank you!

did you tried it without this line? works without it in my config.

Hi @noofel.rouge , yes tried it without that line in extra args but same issue:

❯ nix flake check
error:
       … while checking flake output 'nixosConfigurations'
         at /nix/store/4061vzqzf70923ps03sfhabr0y9appng-source/flake.nix:84:5:
           83|     # NixOS configuration entrypoint
           84|     nixosConfigurations = {
             |     ^
           85|       tbnix = nixpkgs.lib.nixosSystem {

       … while checking the NixOS configuration 'nixosConfigurations.tbnix'
         at /nix/store/4061vzqzf70923ps03sfhabr0y9appng-source/flake.nix:85:7:
           84|     nixosConfigurations = {
           85|       tbnix = nixpkgs.lib.nixosSystem {
             |       ^
           86|         specialArgs = {

       … while evaluating the option `system.build.toplevel':

       … while evaluating definitions from `/nix/store/22r7q7s9552gn1vpjigkbhfgcvhsrz68-source/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `assertions':

       … while evaluating definitions from `/nix/store/xi3dvmqv5mrj0281i9sl4hfpzkwq3cmz-source/nixos/common.nix':

       … while evaluating the module argument `inputs' in "/nix/store/4061vzqzf70923ps03sfhabr0y9appng-source/hosts/tbnix/home.nix":

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

       error: infinite recursion encountered
       at /nix/store/22r7q7s9552gn1vpjigkbhfgcvhsrz68-source/lib/modules.nix:515:28:
          514|         addErrorContext (context name)
          515|           (args.${name} or config._module.args.${name})
             |                            ^
          516|       ) (functionArgs f);

Here is the modified flake.nix

    nixosConfigurations = {
      tbnix = nixpkgs.lib.nixosSystem {
        specialArgs = { 
          inherit system; inherit inputs; inherit nixvim;
        };
        modules = [
          ./hosts/tbnix
	  # nixvim.nixosModules.nixvim
	  # nixvim.homeManagerModules.nixvim
          home-manager.nixosModules.home-manager {
            home-manager.extraSpecialArgs = { inherit homeManager; };
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;

i dont have that line at all. extraSpecialArgs stays unset. you maybe wanna try it.

my config:

inputs = {
  nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-24.11";
  nixvim = {
    url = "github:nix-community/nixvim/nixos-24.11";
    inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = {self, nixpkgs, nixvim}: {
    nixosConfiguration.hostname = nixpkgs.lib.nixosSystem {
      system = "x86_64";
      modules = [
        home-manager.nixos-modules.home-manager {
          home-manager.useGlobalPkgs = true;
          home-manager.useUserPackages = true;
          home-manager.users.username = {pkgs, ...}: {
            imports = [ ./nixvim ]; # folder ./nixvim contains default.nix with configuration
          }
        }
      ];
    };
  };
};

That would be a huge bummer. I have the extraSpecialArgs set for my shortcut variable homeManager for the different directories I use:

let
    homeManager = {
         mod = ./modules;
         df = ./modules/dotfiles;
         cfg = ./modules/dotfiles/config;
    };
  in
...
          home-manager.nixosModules.home-manager {
            home-manager.extraSpecialArgs = { inherit homeManager; }; # shortcut for home manager files

I would need to rewrite a significant portion of my config if that’s the problem :frowning:
Are you sure? If that’s the case, I might have to give up on nixvim for now and try configuring neovim directly :confused: .

Let me know, thanks for looking into this!

i think you can add the nixvim config as a seperate nixos module. here is the simple flake i tried it with:

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
    nixvim = {
      url = "github:nix-community/nixvim/nixos-24.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    home-manager = {
      url = "github:nix-community/home-manager/release-24.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, nixvim, home-manager }: {
    nixosConfiguration.hostname = nixpkgs.lib.nixosSystem {
      system = "x86_64";
      modules = [
        home-manager.nixosModules.home-manager {
          home-manager.useGlobalPkgs = true;
          home-manager.useUserPackages = true;
          home-manager.users.username = {pkgs, ...}: {
            home.packages = [
              pkgs.wget ### example else config
            ];
          };
        }

        home-manager.nixosModules.home-manager {
          home-manager.useGlobalPkgs = true;
          home-manager.useUserPackages = true;
          home-manager.users.username = {pkgs, ...}: {
            programs.nixvim = {
              enable = true;
            };
          };
        }
      ];
    };
  };
}

donk really know if everything i did there is necessary, like the second home-manager.useGlobalPkgs = true;.

It’s infrec’ing because you never passed in inputs, which is exactly what is mentioned in the error.

So, you have to pass it in via specialArgs in the NixOS config (which you appear to have done) AND extraSpecialArgs in the HM config.

Hi @waffle8946 , thanks for looking at this issue. I’m also a bit stumped. The reason I’m asking for help is exactly what you mention, I think I’ve tried every combination. Not sure where I’m going wrong. Unless I’m missing something from your comment, I don’t know what else to try.

You didn’t pass inputs via extraSpecialArgs in the HM config.
Do so.

Ah ok, THAT DID IT! :slight_smile:. As I was writing how I got another error, I figured that out. I use a single flake for two workstations. I fixed ‘tbnix’ workstation config but not my other one, ‘bqnix’. Once I made them the same with inputs in extraSpecialArgs the final error was resolved. Thank you both for the help.

Here are the configs for posterity:

flake.nix

{
  inputs = {

    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

    home-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";

    nixvim.url = "github:nix-community/nixvim";
    nixvim.inputs.nixpkgs.follows = "nixpkgs";

....
  };

  outputs = inputs@{
    nixpkgs,
    home-manager,
    nixvim,
    ...
  }:

  let

    system = "x86_64-linux";

    homeManager = {
         mod = ./modules;
         df = ./modules/dotfiles;
         cfg = ./modules/dotfiles/config;
    };

  in

  {
    # NixOS configuration entrypoint
    nixosConfigurations = {
      tbnix = nixpkgs.lib.nixosSystem {
        specialArgs = { 
          inherit system inputs;
        };
        modules = [
          ./hosts/tbnix
          home-manager.nixosModules.home-manager {
            home-manager.extraSpecialArgs = { 
               inherit homeManager inputs; 
            };
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.fez = import ./hosts/tbnix/home.nix;
          }
        ];

bqnix here...
...

tbnix laptop home.nix called from flake, not much in this file, but it calls the common home.nix

{ inputs, config, lib, pkgs, modulesPath, homeManager, ... }:

{
  imports = [
    ../common/home.nix 
  ];

  home.file = {
...

common home.nix

{ inputs, config, lib, pkgs, modulesPath, homeManager, ... }:

{
  imports = [
    inputs.nixvim.homeManagerModules.nixvim 
    (homeManager.df + "/tmux.nix")
    (homeManager.df + "/lf.nix")
    (homeManager.df + "/zsh.nix")
    (homeManager.df + "/vscode.nix")
    # (homeManager.mod + "/nixvim/nixvimkiktst.nix")
    # (homeManager.mod + "/nixvim/nixvimkik.nix")
    # (homeManager.mod + "/nixvim/neovim.nix")
    # (homeManager.mod + "/nixvim/neovimlsp.nix")
  ];

...

  programs.nixvim = {
    enable = true;
  };


...

  programs.home-manager.enable = true;


...

  home.stateVersion = "24.05";
}