Installing LunarVim

I’m fairly new to Nix (currently only using nix-env). I was trying to create a Nix script to install all the programs I usually use in case I need to start using a new computer (e.g. at work), but I’m not entirely sure how to install things like lunarvim that just use a install.sh script and that’s it.

Their documentation says:

bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/master/utils/installer/install.sh)

So, essentially fetch an url then use bash. Is there a way to do this in Nix? I know of fetchurl and runCommand… yet somehow I don’t understand how to use them! I get a derivation… then what? I feel like nix-pills go straight to compiling c packages and don’t help me much with my use case.

Sorry for this stupid question but I’m at a loss right now.

1 Like

Hey, always great to see people getting started with writing nix stuff :slightly_smiling_face:

Installing applications with a curl-bash-combo like that is viewed critically by a lot of people, (imo) mostly because it’s pretty much impossible to contain the effects. The script could install stuff anywhere or do other complex setup, which is sometimes useful but doesn’t really fit with nix.

I suggest that you download the script and have a look inside. Most of the time, they aren’t doing anything fancy. It’s probably downloading an archive, extracting it and then copying some files.

You can use that information in a derivation. Specifying src will download and extract, and you can override buildPhase, installPhase, … to do the necessary stuff.

I hope that gave you a bit of a direction, let us know how it works out :alien:

1 Like

Hi !

I mostly have the same question and arrived to the same conclusion (I have to write the derivation myself).

However, I have something that I don’t understand very well.

This specific installation script use programming languages package managers in order to install runtime dependencies for neovim. But aren’t programming languages package managers “bad practices in nix” ?

Moreover, if I use programming languages package managers, do they have to be runtime or build dependencies ?

Or do I have to install the languages dependencies as runtime dependencies of neovim?

As the original author of the post I am quite new to nix and I don’t think I grasp everything to make this derivation in the best possible way. Do you any any tips for us ?

Btw as I struggled with this I started my own config based on the awesome nyoom.nvim by user shaunsingh.

1 Like

It may be a disappointment, but the easiest way to run Lunarvim on NixOS is just to run the script, install it in your home folder while skipping all the python and node dependencies it wants to install. That is not very reproducible, but it has the advantage of working.

When running it, you obviously need nvim in your profile as Lunarvim is basically a wrapper and config around nvim. I think this wrapper route also might be the way to go in case you wanted to create a proper nix-native lvim derivation. But I haven’t tried so far.

The actual script that “is” lvim so to speak is living in /home/${USERNAME}/.local/bin/lvim and will just do an exec nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" "$@" plus a few exports.

As for language servers it wants to install, they won’t work for reasons I haven’t investigated. But if you just install the language server via nix, lvim will pick it up. I for instance like to run these inside devShells or nix-shells I create for projects.

Most likely because they were built with their dynamic linker in /usr/bin/ld-linux.so, as it is on your usual fhs distro. You can confirm this by running ldd on the binaries, but I’m fairly sure that’s the case. Other libraries may be missing too.

Most binaries downloaded from the internet won’t work on NixOS, because that dynamic linker is in/nix/store here.

There’s a wiki entry here about all of that: Packaging/Binaries - NixOS Wiki

It’s a shame so many programs just download random binaries from the internet. It increases the risk of supply chain attacks and relies on the internet working when you want to use the application.

I fully agree on the risk aspect. However it is possible to disable the auto-download entirely by setting lvim.lsp.automatic_servers_installation to false in your config. You then can setup the language servers manually, which should just get picked up if you are running a nix-shell with, let’s say pyright or typescript-language-server

1 Like

Do you have spme where your nyooom nix conifg?

It has been finally added to nixpkgs.

https://search.nixos.org/packages?channel=23.11&from=0&size=50&sort=relevance&type=packages&query=lunarvim

3 Likes