Configuring neovim with nixvim

I’ve added nixvim to inputs and nixvim.nix module in flake.nix:

{
  description = "Configurations";

  inputs = {
    nixpkgs.url        = "nixpkgs/nixos-unstable";
    nixpkgs-stable.url = "nixpkgs/nixos-23.11";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixvim = {
      url = "github:nix-community/nixvim";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  outputs = { nixpkgs, nixpkgs-stable, home-manager, nixvim, ... }:
    let
      Variables = rec {
        username    = "mee";
        hostname    = "nixos";
        system      = "x86_64-linux";
        pkgs        = nixpkgs.legacyPackages.${system};
        pkgs-stable = nixpkgs-stable.legacyPackages.${system};
        tuigreet    = "${pkgs.greetd.tuigreet}/bin/tuigreet";
        session     = "${pkgs.hyprland}/bin/Hyprland";
      };
    in
    {
      nixosConfigurations = {
        nixos = nixpkgs.lib.nixosSystem {
          specialArgs = { inherit Variables; };
          modules = [
            ./configuration.nix
            ./hardware-configuration.nix
          ];
        };
      };
      homeConfigurations = {
        mee = home-manager.lib.homeManagerConfiguration {
          pkgs = Variables.pkgs;
          extraSpecialArgs = { inherit Variables; };
          modules = [
            ./home.nix
            ./modules/home/xdg.nix
            ./modules/home/gtk.nix
            ./modules/home/nixvim.nix
          ];
        };
      };
    };
}

Here is nixvim.nix module:

{ ... }:

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

error: The option ‘programs.nixvim’ does not exist. In …nixvim.nix
or error: cached failure of attribute ‘homeConfigurations.mee.activationPackage’

Is there any way to fix this, so that the configuration is in similar fashion as the rest of the configuration? I managed to run it as a standalone flake and as home module with nixvim import in home.nix. Just looking for simplifications to my overall configuration.

homeConfigurations = {
  mee = home-manager.lib.homeManagerConfiguration {
    pkgs = Variables.pkgs;
    extraSpecialArgs = { inherit Variables; };
    modules = [
      ./home.nix
      ./modules/home/xdg.nix
      ./modules/home/gtk.nix
      ./modules/home/nixvim.nix

      nixvim.nixosModules.default
    ];
  };
};

Also, please don’t override the pkgs in _module.args, that turns off all the NixOS/home-manager module integration for that and will be very confusing for anyone helping you.

Do you mean that it’s better idea to add those home modules to home.nix?

nixvim.nixosModules.default

With nixvim added to outputs:
error: attribute ‘default’ missing

Oh, fair, they call their module nixvim:

homeConfigurations = {
  mee = home-manager.lib.homeManagerConfiguration {
    pkgs = Variables.pkgs;
    extraSpecialArgs = { inherit Variables; };
    modules = [
      ./home.nix
      ./modules/home/xdg.nix
      ./modules/home/gtk.nix
      ./modules/home/nixvim.nix

      nixvim.nixosModules.nixvim
    ];
  };
};

No, your Variables.pkgs will override the pkgs in your entire NixOS configuration, breaking your nixpkgs options, among likely other things.

pkgs = nixpkgs.legacyPackages.x86_64-linux;
Is that right? Without specifying pkgs for home it will complain about it.

nixvim.nixosModules.nixvim

It’s better, but still some error:
The option ‘environment’ does not exist. -In ‘/nix/store…flake.nix#nixosModules.nixvim’

This is fine. These are not:

Because that will place your Variables.pkgs in _modules.arg.pkgs, overwriting the normal pkgs in the module system.

Going to need more context on that error, that’s a different thing entirely.

I made it like that to pass variables into modules just like this dude - flake.nix Not sure how to pass them in one place other than what I do now.

The rest part of that error if that helps:

{
  _type = "if";
 condition = true;
 content = {
   systemPackages = [
...

or now:
error: cached failure of attribute ‘homeConfigurations.mee.acivationPackage’

Maybe those pkgs overrides are messing my configuration.

You can do this instead, with no effective changes (except that the nixpkgs.* options will no longer be broken):

  outputs = { nixpkgs, nixpkgs-stable, home-manager, nixvim, ... }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};

      Variables = {
        inherit system;
        username = "mee";
        hostname = "nixos";
        pkgs-stable = nixpkgs-stable.legacyPackages.${system};
        tuigreet    = "${pkgs.greetd.tuigreet}/bin/tuigreet";
        session     = "${pkgs.hyprland}/bin/Hyprland";
      };
    in
    {
      nixosConfigurations = {
        nixos = nixpkgs.lib.nixosSystem {
          specialArgs = {
            inherit Variables;
          };
          modules = [
            ./configuration.nix
            ./hardware-configuration.nix
          ];
        };
      };
      homeConfigurations = {
        mee = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          extraSpecialArgs = { inherit Variables; };
          modules = [
            ./home.nix
            ./modules/home/xdg.nix
            ./modules/home/gtk.nix
            ./modules/home/nixvim.nix
          ];
        };
      };
    };

I suspect that a lot of the things you set in Variables could be removed entirely with some use of the NixOS module system, (e.g. config.networking.hostName), ultimately resulting in better UX, but I’m just pointing out the actual potential footgun rather than giving you a full code review.

Could you please share the full errors as nix outputs them (no need to add the --trace, just everything from your command down to the end)?

Nix will cache your builds, and if you have a build that failed, it will tell you that it has already failed before and it doesn’t need to rebuild them.

Annoyingly this also makes it hard to recover the error message (because for some reason that isn’t stored, there are some complaints about this), but just adding a single newline somewhere in your code will let you run the build again.

1 Like

Tnx, I modify config to not mess with nixpkgs options.

error:
       … while evaluating a branch condition

         at /nix/store/m9s94alic7s2r6v47p7lwfj58ibc076a-source/lib/lists.nix:57:9:

           56|       fold' = n:
           57|         if n == len
             |         ^
           58|         then nul

       … while calling the 'length' builtin

         at /nix/store/m9s94alic7s2r6v47p7lwfj58ibc076a-source/lib/lists.nix:55:13:

           54|     let
           55|       len = length list;
             |             ^
           56|       fold' = n:

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

       error: The option `environment' does not exist. Definition values:
       - In `/nix/store/k897af00nzlz4ylxr5vakzpcvh6m3rnn-source/flake.nix#nixosModules.nixvim':
           {
             _type = "if";
             condition = true;
             content = {
               systemPackages = [
           ...

Ah, yes, my bad. Of course you don’t add the NixOS module to your home-manager configuration:

homeConfigurations = {
  mee = home-manager.lib.homeManagerConfiguration {
    inherit pkgs;
    extraSpecialArgs = { inherit Variables; };
    modules = [
      ./home.nix
      ./modules/home/xdg.nix
      ./modules/home/gtk.nix
      ./modules/home/nixvim.nix

      nixvim.homeManagerModules.nixvim
    ];
  };
};
1 Like

hehe good one : D
Tnx, tnx, tnx, now it builds! :smiley: