Neovim config read-only

I started using neovim, and created a repo with all of my configs. I did this because I use many non-nix systems and its easier for me this way.

{
  programs.neovim = {
    enable = true;

    withNodeJs = true;
    withPython3 = true;
    withRuby = true;
  };
}

I cloned the repo using this in home manager

let
  home-manager = builtins.fetchTarball
    "https://github.com/nix-community/home-manager/archive/release-23.05.tar.gz";
in {
  imports = [ "${home-manager}/nixos" ];
  home-manager.users.redhawk = { config, pkgs, ... }: {
    home.stateVersion = "23.05";

    xdg = {
      configFile."nvim".source = builtins.fetchGit {
        url = "https://github.com/Redhawk18/neovim-config";
      };
    };
  };
}

This worked until I got this error from Lazy, my nvim package manager.

Error detected while processing /nix/store/j70xlivqkngjy2n8yd44mnahg9apv9yh-source/init.lua:
E5113: Error while calling lua chunk: ...local/share/nvim/lazy/lazy.nvim/lua/lazy/manage/lock.lua:12: /home/redhawk/.config/nvim/lazy-lock.json: Read-only file system
stack traceback:
        [C]: in function 'assert'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/manage/lock.lua:12: in function 'update'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/manage/init.lua:93: in function 'cb'
        ...cal/share/nvim/lazy/lazy.nvim/lua/lazy/manage/runner.lua:158: in function 'install'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:76: in function 'install_missing'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:44: in function 'setup'
        ...dhawk/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:100: in function 'setup'
        /home/redhawk/.config/nvim/lua/package_manager.lua:14: in main chunk
        [C]: in function 'require'
        /nix/store/j70xlivqkngjy2n8yd44mnahg9apv9yh-source/init.lua:3: in main chunk
Press ENTER or type command to continue

While I know this is due to nix filesystem, I have no idea how to actually fix it.

also the nil lsp for nvim wont install, but it does on my main non-nixos system?

Maybe you can link the lua/ and init.lua seperately instead of linking the whole repo. Or set another lockfile path.

anyway to do this? trying to do this the nix way. or do you just mean normal linux soft linking?

I thought you can do something like this

      configFile."nvim/lua".source = "${builtins.fetchGit {
        url = "https://github.com/Redhawk18/neovim-config";
      }}/lua";

Where does this clone the repo to then?

The repo is always cloned into the nix store. The difference is only in how you link the files to your home.

this made no difference, it’s still read only

any ideas? no one seems to know

I manage my neovim configs using home-manager. From my perspective, that means I acknowledge that any artifacts downloaded by home-manager are read-only, as that is how nix works.

It sounds like you want to re-use the configs across distros or platforms, and that makes sense. Could you just clone your repos into your home directory somewhere, then include them from your home-manager neovim config (using a lua require for instance)? The actual clone would be done manually, or in a shell script, or even in the neovim config. Would that serve you well?

Alternatively, you can keep the way you are doing it now, with the understanding that the cloned repo in the nix store isn’t the one you edit. Instead, you edit another repo clone, then commit and push, then run home-manager switch to update. I hope that makes sense.

Personally, when I switched to home-manager, I decided to use home-manager across distros, so my home-manager repo is the source of truth for my neovim configs.

1 Like

I agree with bowmanjd, you’ll eventually have to make a choice between declarative and imperative.

Although the following workaround could work (from Tradeoffs of using home manager for neovim plugins : NixOS)

[–]professorfinesser_[S] 4 points 6 months ago

Hey sorry for the late response!

I had the same exact issue with updating lazy-lock.json. The best solution I found is to use mkOutOfStoreSymLink with home-manager (see discussion I found). I have this in my config:

home.file.“./.config/nvim”.source = config.lib.file.mkOutOfStoreSymlink “${config.home.homeDirectory}/nix/home-manager/lib/nvim/config”

where you pass the absolute path of your nvim config directory to it.

Unfortunately, from what I saw a month ago mkOutOfStoreSymLink doesn’t seem to work on MacOS.

1 Like

mkOutOfStoreSymlink is the correct solution here when you need ongoing mutability, and it does work fine on Darwin.

Yeah, I do it as a stand alone repo because it works on every platform this way, even Windows. :slight_smile: