Skip to content

Commit

Permalink
programs.neovim: use extraConfig instead of directly changing init.vim (
Browse files Browse the repository at this point in the history
#58)

Changing init.vim does not work any longer because HM 22.11 has moved to using lua by default, so the file no longer exists.
  • Loading branch information
kalbasit authored Mar 2, 2023
1 parent 3cbcf53 commit 84adb94
Showing 1 changed file with 10 additions and 35 deletions.
45 changes: 10 additions & 35 deletions modules/programs/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,26 @@ in
includeKeyboardLayout = true;
includeTheme = true;
extraOptions = {

extraConfig = mkOption {
type = types.lines;
default = "";
example = ''
set nocompatible
set nobackup
'';
description = ''
Custom vimrc lines.
'';
};

rcheader = mkOption {
extraLuaConfig = mkOption {
type = types.lines;
default = "";
description = ''
Lines added to the top of the rc file.
'';
apply = lines: ''
" rcheader {{{
${lines}
" }}}
example = ''
vim.opt.nobackup = true
'';
};

rcfooter = mkOption {
type = types.lines;
default = "";
description = ''
Lines added to the bottom of the rc file.
'';
apply = lines: ''
" rcfooter {{{
${lines}
" }}}
Custom lua lines.
'';
};

Expand Down Expand Up @@ -83,14 +68,6 @@ in
};

config = mkIf cfg.enable (mkMerge [
# make a snippet in the header for the mapleader
(mkIf (cfg.mapleader != null) {
soxin.programs.neovim.rcheader = ''
" set the mapleader globally
let mapleader = "${cfg.mapleader}"
'';
})

# add all plugins installed by themes
{ soxin.programs.neovim.plugins = cfg.theme.plugins; }

Expand Down Expand Up @@ -127,7 +104,11 @@ in

programs.neovim = {
enable = true;
inherit (cfg) extraConfig plugins;
inherit (cfg) extraLuaConfig plugins;

extraConfig = ""
+ (optionalString (cfg.mapleader != null) ''let mapleader = "${cfg.mapleader}"'')
+ cfg.extraConfig;

# Add the Python's neovim plugin
extraPython3Packages = ps: with ps; [ pynvim ];
Expand All @@ -136,12 +117,6 @@ in
// (genAttrs [ "viAlias" "vimAlias" "vimdiffAlias" ] (name: true))
# Add support for NodeJS, Python 2 and 3 as well as Ruby
// (genAttrs [ "withNodeJs" "withPython3" "withRuby" ] (name: true));

# inject the header/footer to the rcfile on home-manager
xdg.configFile."nvim/init.vim".text = mkMerge [
(mkBefore cfg.rcheader)
(mkAfter cfg.rcfooter)
];
})
]);
}

0 comments on commit 84adb94

Please sign in to comment.