Permission Denied Errors with neovim plugin

I am attempting to use the sonokai plugin with neovim. My config looks like this:

  programs.neovim.plugins = with pkgs.vimPlugins; [
    {
      plugin = sonokai;
      config = ''
        if has('termguicolors')
          set termguicolors
        endif
        let g:sonokai_style = 'shusia'
        let g:sonokai_enable_italic = 1
        let g:sonokai_better_performance = 1
        colorscheme sonokai
      '';
    }
  ];

When I open Neovim, I get a string of errors related to failures to write to the nix store:

Error detected while processing function sonokai#ft_gen[10]..sonokai#ft_write:                                                                        
line    5:                                                                                                                                            
E739: Cannot create directory /nix/store/l0d7r7djq05bn3clh79i7f43x9p3nzpa-vimplugin-sonokai-2021-03-22/share/vim-plugins/sonokai/after: permission den
ied                                                                                                                                                   
line    6:                                                                                                                                            
E482: Can't open file /nix/store/l0d7r7djq05bn3clh79i7f43x9p3nzpa-vimplugin-sonokai-2021-03-22/share/vim-plugins/sonokai/after/ftplugin/vim-plug/sonok
ai.vim for writing: no such file or directory                                                                                                         
line   11:                                                                                                                                            
E482: Can't open file /nix/store/l0d7r7djq05bn3clh79i7f43x9p3nzpa-vimplugin-sonokai-2021-03-22/share/vim-plugins/sonokai/after/ftplugin/vim-plug/sonok
ai.vim for writing: no such file or directory                                                                                                         
line   22:                                                                                                                                            
E482: Can't open file /nix/store/l0d7r7djq05bn3clh79i7f43x9p3nzpa-vimplugin-sonokai-2021-03-22/share/vim-plugins/sonokai/after/ftplugin/vim-plug/sonok
ai.vim for writing: no such file or directory                                                                                                         
line   28:                                                                                                                                            
E482: Can't open file /nix/store/l0d7r7djq05bn3clh79i7f43x9p3nzpa-vimplugin-sonokai-2021-03-22/share/vim-plugins/sonokai/after/ftplugin/vim-plug/sonok
ai.vim for writing: no such file or directory                                                                                                         
line    5:                                                                                                                                            
E739: Cannot create directory /nix/store/l0d7r7djq05bn3clh79i7f43x9p3nzpa-vimplugin-sonokai-2021-03-22/share/vim-plugins/sonokai/after: permission den
ied                                                                                                                                                   
line    6:                                      
[... elided ...]

Looking at the sonokai source, the plugin attempts to create some files when it is loaded. I assume that’s not working because the store is read-only.

I also tried making the plugin optional and loading manually via packadd! but this results in the same issues.

Is my assumption correct? Can anyone think of a work-around for this?

Thanks!

I’m not familiar with how programs.neovim.plugins works. That is from the home-manager neovim module, right?

I’m using overrides without home-manager on NixOS, so I put this plugin into my configuration file for neovim, and it seemed to work perfectly fine without those error messages, but I am not sure if it will work with home-manager:

{ config, pkgs, ...}:

let
  customPlugins.sonokai = pkgs.vimUtils.buildVimPlugin {
    name = "sonokai";
    src = pkgs.fetchFromGitHub {
      owner = "sainnhe";
      repo = "sonokai";
      rev = "78f1b14ad18b043eb888a173f4c431dbf79462d8";
      sha256 = "0spnpzr874ad9jpawcgydfm242wq55ychcky14f1qa09svsrdiv0";
    };
  };
in {
  nixpkgs.config.packageOverrides = pkgs: with pkgs; rec {
    neovim_with_plugins = neovim.override {
      configure = {
        packages.neovim = with pkgs.vimPlugins // customPlugins; { start = [
          sonokai
        ];
      };
    };
  };
};

I haven’t keep completely up to date with everything with nix, so it’s completely possible that there are better ways now of doing the same thing.

1 Like

That’s right. I am using the home-manager module. I wonder if this is something home-manager specific then.

I learned that the sonokai theme only attempts to write files if you enable g:sonokai_better_performance. Disabling that fixed the file write issues however I then ended up in a situation where the theme was not automatically getting loaded.

I ended up switching to installing VimPlug and using that to install sonokai. It’s not as elegant, or reproducible, but it works. :man_shrugging: