NixVim Performance. Flakes in Flakes

Hi folks,

I’m getting into configuring my own NixVim setup and need some guidance around performance.

I see there’s LazyLoading (beta) support etc, but before getting to any of that I wanted to test the startup time with nothing else installed.

I created a blank NixVim install using
nix flake init --template github:nix-community/nixvim

After a nix run in this directory, it installs an opens.
I close it, and then nix run again but this time it needs no downloads/install, so it’s this startup time which I’d like to measure.

Q1 - This seems to take ~ 5 seconds. That seems too high for a blank install no?
I’m on expensive hardware (Mac M4 Pro & Intel i9 13900)

Q2 - How do I better quantify this startup time, and look at activity logs to debug it?

Yeah, it will include some nix eval time to let nix figure out what it should run (and if it’s cached and whatnot). The eval cache should make that fairly quick, but it’ll impact your start time.

I’d recommend using nix build and timing the actual binary instead of including nix stuff in your timings, since that won’t in practice be part of your everyday use.

That’s more of a vim question, can’t chime in, sorry.

2 Likes

I’m also open to “Just use NeoVim with Nix” type comments if people can explain the setup and include GH references.

Goal is just to be as declarative as possible

Would there be a way to install the built flake like a package, to reduce any such nix stuff at time of invocation?

Not sure if that Q makes sense, it does in my head

Yes, enabling that kind of thing is the point of flakes. If you do this, you should turn your whole NixOS/home-manager/nix-darwin configuration (depending on what deployment tool you use) into a flake and add your nixvim flake to your inputs, and then pass it through specialArgs/extraSpecialArgs and eventually into the *Packages of your configuration.

… or simply embed your nixvim configuration into your deployment flake, which is a fair bit less cumbersome to maintain.

If you’re asking because you’re currently using nix-env to install things, I’d strongly recommend you stop doing that, and switch to one of the above declarative options. home-manager is designed for this type of dotfile installation. You can use nix profile instead if you insist, but once you’re starting to maintain deployments with nix I’d really recommend the declarative options.

Great! I’ve yet to fully wrap my head around flakes, and overlays…

I’m not using nix-env, that would defeat my whole goal of “declarative everything in a repo” :smiley:

I understand the suggestions thankyou (except maybe the *Packages part, for now). I will give both a try.

There does seem to be merit in keeping a bigger isolated project such as this in its own directory & flake, theoretically making it more portable to others.

You can always create and use an output for your nixvim config to depend on it in another project if you so desire, even if it is part of your deployment flake.

While I understand the thought, the reality is that vim configurations are very personal unless you go out of your way to create a new vim distro. Yours will not be used by others. Deployment flakes like this are very much consumers, splitting them up just adds an API surface you now need to maintain.

Trust me, been there, done that, you’re going to tie yourself into a lot of fiddly maintenance for no real gain if you go down the separate repo path :wink:

Definitely no desire to split up repos.

The thinking behind this was just to keep it in its own directory (in the same repo)

Instead of making it a deeply nested module somewhere down here

Only because I thought this way I can easier iterate on the nixvim flake with nix run and then only have to rebuild switch when I’m happy with it.

So it turned out incredibly easy to install the nixvim flake as a package into my deployment flake, just as you suggested.

nvim launches it, and startup time is immeasurably small compared to the nix run directly on the flake

1 Like
      url = "path:./flakes/nixvim";

Huh, I missed the addition of relative flakes, this not working used to be a very commonly asked question.

1 Like

Worked on nix-darwin, just tried to apply it on NixOS and I think I hit what you’re referring to :frowning:

Then found this perculiar fix, and it worked…

Sow now, works on both, with:

my-nixvim = {
      url = "path:flakes/nixvim";
    };

Some plugin exists to do that.

This is the one that I use.

1 Like