nixvim: support standalone nixvim

This represents a major rearchitecture for nixvim, so I'm leaving this up to track the progress for now, and to serve as a reference for any breaking changes during transition.

The main change is, of course, being able to use nixvim standalone. To do this, you should use the new build function, which takes in two arguments: the system architecture (e.g. x86_64-linux) and the configuration. For the new configuration, do not use the programs.nixvim. prefix.

For module development, the main change is that you should no longer prefix your modules with programs.nixvim..
This commit is contained in:
Pedro Alves 2022-09-18 11:19:23 +01:00 committed by GitHub
parent bd6f978d51
commit 4ddd3969e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 1410 additions and 904 deletions

View file

@ -1,12 +1,12 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.comment-nvim;
cfg = config.plugins.comment-nvim;
helpers = import ../helpers.nix { inherit lib; };
in
{
options = {
programs.nixvim.plugins.comment-nvim = {
plugins.comment-nvim = {
enable = mkEnableOption "Enable comment-nvim";
padding = mkOption {
type = types.nullOr types.bool;
@ -24,7 +24,7 @@ in
default = null;
};
toggler = mkOption {
type = types.nullOr (types.submodule ({...}: {
type = types.nullOr (types.submodule ({ ... }: {
options = {
line = mkOption {
type = types.str;
@ -42,7 +42,7 @@ in
default = null;
};
opleader = mkOption {
type = types.nullOr (types.submodule ({...}: {
type = types.nullOr (types.submodule ({ ... }: {
options = {
line = mkOption {
type = types.str;
@ -60,7 +60,7 @@ in
default = null;
};
mappings = mkOption {
type = types.nullOr (types.submodule ({...}: {
type = types.nullOr (types.submodule ({ ... }: {
options = {
basic = mkOption {
type = types.bool;
@ -85,20 +85,20 @@ in
};
};
config = let
setupOptions = {
padding = cfg.padding;
sticky = cfg.sticky;
ignore = cfg.ignore;
toggler = cfg.toggler;
opleader = cfg.opleader;
mappings = cfg.mappings;
};
in mkIf cfg.enable {
programs.nixvim = {
config =
let
setupOptions = {
padding = cfg.padding;
sticky = cfg.sticky;
ignore = cfg.ignore;
toggler = cfg.toggler;
opleader = cfg.opleader;
mappings = cfg.mappings;
};
in
mkIf cfg.enable {
extraPlugins = [ pkgs.vimPlugins.comment-nvim ];
extraConfigLua =
''require("Comment").setup${helpers.toLuaObject setupOptions}'';
};
};
}

View file

@ -1,20 +1,18 @@
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.commentary;
cfg = config.plugins.commentary;
in
{
# TODO Add support for aditional filetypes. This requires autocommands!
options = {
programs.nixvim.plugins.commentary = {
plugins.commentary = {
enable = mkEnableOption "Enable commentary";
};
};
config = mkIf cfg.enable {
programs.nixvim = {
extraPlugins = [ pkgs.vimPlugins.vim-commentary ];
};
extraPlugins = [ pkgs.vimPlugins.vim-commentary ];
};
}

View file

@ -1,13 +1,13 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.dashboard;
cfg = config.plugins.dashboard;
helpers = import ../helpers.nix { inherit lib; };
in
{
options = {
programs.nixvim.plugins.dashboard = {
plugins.dashboard = {
enable = mkEnableOption "Enable dashboard";
header = mkOption {
@ -124,8 +124,8 @@ in
};
filteredOptions = filterAttrs (_: v: !isNull v) options;
in mkIf cfg.enable {
programs.nixvim = {
in
mkIf cfg.enable {
extraPlugins = [ pkgs.vimPlugins.dashboard-nvim ];
extraConfigLua = ''
local dashboard = require("dashboard")
@ -135,5 +135,4 @@ in
filteredOptions)}
'';
};
};
}

View file

@ -1,20 +1,18 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.easyescape;
cfg = config.plugins.easyescape;
helpers = import ../helpers.nix { inherit lib; };
in
in
{
options = {
programs.nixvim.plugins.easyescape = {
plugins.easyescape = {
enable = mkEnableOption "Enable easyescape";
};
};
config = mkIf cfg.enable {
programs.nixvim = {
extraPlugins = with pkgs.vimPlugins; [
vim-easyescape
];
};
extraPlugins = with pkgs.vimPlugins; [
vim-easyescape
];
};
}

View file

@ -1,12 +1,12 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.floaterm;
let
cfg = config.plugins.floaterm;
helpers = import ../helpers.nix { inherit lib; };
in
{
options = {
programs.nixvim.plugins.floaterm = {
plugins.floaterm = {
enable = mkEnableOption "Enable floaterm";
shell = mkOption {
type = types.nullOr types.str;
@ -64,23 +64,21 @@ in
};
};
config = mkIf cfg.enable {
programs.nixvim = {
extraPlugins = with pkgs.vimPlugins; [
vim-floaterm
];
globals = {
floaterm_shell = mkIf (!isNull cfg.shell) cfg.shell;
floaterm_title = mkIf (!isNull cfg.title) cfg.title;
floaterm_wintype = mkIf (!isNull cfg.winType) cfg.winType;
floaterm_width = mkIf (!isNull cfg.winWidth) cfg.winWidth;
floaterm_height = mkIf (!isNull cfg.winHeight) cfg.winHeight;
floaterm_borderchars = mkIf (!isNull cfg.borderChars) cfg.borderChars;
floaterm_rootmarkers = mkIf (!isNull cfg.rootMarkers) cfg.rootMarkers;
floaterm_opener = mkIf (!isNull cfg.opener) cfg.opener;
floaterm_autoclose = mkIf (!isNull cfg.autoClose) cfg.autoClose;
floaterm_autohide = mkIf (!isNull cfg.autoHide) cfg.autoHide;
floaterm_autoInsert = mkIf (!isNull cfg.autoInsert) cfg.autoInsert;
};
extraPlugins = with pkgs.vimPlugins; [
vim-floaterm
];
globals = {
floaterm_shell = mkIf (!isNull cfg.shell) cfg.shell;
floaterm_title = mkIf (!isNull cfg.title) cfg.title;
floaterm_wintype = mkIf (!isNull cfg.winType) cfg.winType;
floaterm_width = mkIf (!isNull cfg.winWidth) cfg.winWidth;
floaterm_height = mkIf (!isNull cfg.winHeight) cfg.winHeight;
floaterm_borderchars = mkIf (!isNull cfg.borderChars) cfg.borderChars;
floaterm_rootmarkers = mkIf (!isNull cfg.rootMarkers) cfg.rootMarkers;
floaterm_opener = mkIf (!isNull cfg.opener) cfg.opener;
floaterm_autoclose = mkIf (!isNull cfg.autoClose) cfg.autoClose;
floaterm_autohide = mkIf (!isNull cfg.autoHide) cfg.autoHide;
floaterm_autoInsert = mkIf (!isNull cfg.autoInsert) cfg.autoInsert;
};
};
}

View file

@ -1,24 +1,22 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.comment-nvim;
cfg = config.plugins.comment-nvim;
defs = import ../plugin-defs.nix { inherit pkgs; };
in
{
options = {
programs.nixvim.plugins.intellitab = {
plugins.intellitab = {
enable = mkEnableOption "intellitab.nvim";
};
};
config = mkIf cfg.enable {
programs.nixvim = {
extraPlugins = [ defs.intellitab-nvim ];
extraPlugins = [ defs.intellitab-nvim ];
maps.insert."<Tab>" = "<CMD>lua require([[intellitab]]).indent()<CR>";
plugins.treesitter = {
indent = true;
};
maps.insert."<Tab>" = "<CMD>lua require([[intellitab]]).indent()<CR>";
plugins.treesitter = {
indent = true;
};
};
}

View file

@ -2,11 +2,12 @@
with lib;
let
cfg = config.programs.nixvim.plugins.mark-radar;
cfg = config.plugins.mark-radar;
helpers = import ../helpers.nix { inherit lib; };
defs = import ../plugin-defs.nix { inherit pkgs; };
in {
options.programs.nixvim.plugins.mark-radar = {
in
{
options.plugins.mark-radar = {
enable = mkEnableOption "Enable mark-radar";
highlight_background = mkOption {
@ -30,19 +31,19 @@ in {
};
};
config = let
opts = helpers.toLuaObject {
inherit (cfg) highlight_group background_highlight_group;
set_default_mappings = cfg.set_default_keybinds;
background_highlight = cfg.highlight_background;
};
in mkIf cfg.enable {
programs.nixvim = {
config =
let
opts = helpers.toLuaObject {
inherit (cfg) highlight_group background_highlight_group;
set_default_mappings = cfg.set_default_keybinds;
background_highlight = cfg.highlight_background;
};
in
mkIf cfg.enable {
extraPlugins = [ defs.mark-radar ];
extraConfigLua = ''
require("mark-radar").setup(${opts})
'';
};
};
}

View file

@ -1,15 +1,15 @@
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.notify;
cfg = config.plugins.notify;
helpers = import ../helpers.nix { lib = lib; };
icon = mkOption {
type = types.nullOr types.str;
default = null;
};
in
in
{
options.programs.nixvim.plugins.notify = {
options.plugins.notify = {
enable = mkEnableOption "Enable notify";
stages = mkOption {
@ -43,31 +43,31 @@ in
};
});
description = "Icons for the different levels";
default = {};
default = { };
};
};
config = let
setupOptions = with cfg; {
stages = stages;
timeout = timeout;
background_color = backgroundColor;
minimum_width = minimumWidth;
icons = with icons; {
ERROR = error;
WARN = warn;
INFO = info;
DEBUG = debug;
TRACE = trace;
config =
let
setupOptions = with cfg; {
stages = stages;
timeout = timeout;
background_color = backgroundColor;
minimum_width = minimumWidth;
icons = with icons; {
ERROR = error;
WARN = warn;
INFO = info;
DEBUG = debug;
TRACE = trace;
};
};
};
in mkIf cfg.enable {
programs.nixvim = {
in
mkIf cfg.enable {
extraPlugins = [ pkgs.vimPlugins.nvim-notify ];
extraConfigLua = ''
vim.notify = require('notify');
require('notify').setup(${helpers.toLuaObject setupOptions})
'';
};
};
}

View file

@ -1,11 +1,11 @@
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.nvim-autopairs;
cfg = config.plugins.nvim-autopairs;
helpers = import ../helpers.nix { lib = lib; };
in
{
options.programs.nixvim.plugins.nvim-autopairs = {
options.plugins.nvim-autopairs = {
enable = mkEnableOption "Enable nvim-autopairs";
pairs = mkOption {
@ -39,21 +39,21 @@ in
};
};
config = let
options = {
pairs_map = cfg.pairs;
disable_filetype = cfg.disabledFiletypes;
break_line_filetype = cfg.breakLineFiletypes;
html_break_line_filetype = cfg.htmlFiletypes;
ignored_next_char = cfg.ignoredNextChar;
};
in mkIf cfg.enable {
programs.nixvim = {
config =
let
options = {
pairs_map = cfg.pairs;
disable_filetype = cfg.disabledFiletypes;
break_line_filetype = cfg.breakLineFiletypes;
html_break_line_filetype = cfg.htmlFiletypes;
ignored_next_char = cfg.ignoredNextChar;
};
in
mkIf cfg.enable {
extraPlugins = [ pkgs.vimPlugins.nvim-autopairs ];
extraConfigLua = ''
require('nvim-autopairs').setup(${helpers.toLuaObject options})
'';
};
};
}

View file

@ -1,11 +1,11 @@
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.nvim-tree;
cfg = config.plugins.nvim-tree;
helpers = import ../helpers.nix { lib = lib; };
in
{
options.programs.nixvim.plugins.nvim-tree = {
options.plugins.nvim-tree = {
enable = mkEnableOption "Enable nvim-tree";
disableNetrw = mkOption {
@ -14,7 +14,7 @@ in
description = "Disable netrw";
};
hijackNetrw = mkOption {
hijackNetrw = mkOption {
type = types.nullOr types.bool;
default = null;
description = "Hijack netrw";
@ -72,18 +72,20 @@ in
description = "Enable diagnostics";
};
icons = let
diagnosticOption = desc: mkOption {
type = types.nullOr types.str;
default = null;
description = desc;
icons =
let
diagnosticOption = desc: mkOption {
type = types.nullOr types.str;
default = null;
description = desc;
};
in
{
hint = diagnosticOption "Hints";
info = diagnosticOption "Info";
warning = diagnosticOption "Warning";
error = diagnosticOption "Error";
};
in {
hint = diagnosticOption "Hints";
info = diagnosticOption "Info";
warning = diagnosticOption "Warning";
error = diagnosticOption "Error";
};
};
updateFocusedFile = {
@ -201,57 +203,58 @@ in
};
};
config = let
options = {
disable_netrw = cfg.disableNetrw;
hijack_netrw = cfg.hijackNetrw;
open_on_setup = cfg.openOnSetup;
ignore_ft_on_setup = cfg.ignoreFtOnSetup;
auto_close = cfg.autoClose;
open_on_tab = cfg.openOnTab;
hijack_cursor = cfg.hijackCursor;
update_cwd = cfg.updateCwd;
update_to_buf_dir = {
enable = cfg.updateToBufDir.enable;
auto_open = cfg.updateToBufDir.autoOpen;
};
diagnostics = cfg.diagnostics;
updateFocusedFile = {
enable = cfg.updateFocusedFile.enable;
update_cwd = cfg.updateFocusedFile.updateCwd;
ignore_list = cfg.updateFocusedFile.ignoreList;
};
system_open = cfg.systemOpen;
filters = cfg.filters;
git = cfg.git;
view = {
width = cfg.view.width;
height = cfg.view.height;
hide_root_folder = cfg.view.hideRootFolder;
side = cfg.view.side;
auto_resize = cfg.view.autoResize;
mappings = {
custom_only = cfg.view.mappings.customOnly;
list = cfg.view.mappings.list;
config =
let
options = {
disable_netrw = cfg.disableNetrw;
hijack_netrw = cfg.hijackNetrw;
open_on_setup = cfg.openOnSetup;
ignore_ft_on_setup = cfg.ignoreFtOnSetup;
auto_close = cfg.autoClose;
open_on_tab = cfg.openOnTab;
hijack_cursor = cfg.hijackCursor;
update_cwd = cfg.updateCwd;
update_to_buf_dir = {
enable = cfg.updateToBufDir.enable;
auto_open = cfg.updateToBufDir.autoOpen;
};
diagnostics = cfg.diagnostics;
updateFocusedFile = {
enable = cfg.updateFocusedFile.enable;
update_cwd = cfg.updateFocusedFile.updateCwd;
ignore_list = cfg.updateFocusedFile.ignoreList;
};
system_open = cfg.systemOpen;
filters = cfg.filters;
git = cfg.git;
view = {
width = cfg.view.width;
height = cfg.view.height;
hide_root_folder = cfg.view.hideRootFolder;
side = cfg.view.side;
auto_resize = cfg.view.autoResize;
mappings = {
custom_only = cfg.view.mappings.customOnly;
list = cfg.view.mappings.list;
};
number = cfg.view.number;
relativenumber = cfg.view.relativenumber;
signcolumn = cfg.view.signcolumn;
};
trash = {
cmd = cfg.trash.cmd;
require_confirm = cfg.trash.requireConfirm;
};
number = cfg.view.number;
relativenumber = cfg.view.relativenumber;
signcolumn = cfg.view.signcolumn;
};
trash = {
cmd = cfg.trash.cmd;
require_confirm = cfg.trash.requireConfirm;
};
};
in mkIf cfg.enable {
programs.nixvim = {
in
mkIf cfg.enable {
extraPlugins = with pkgs.vimPlugins; [
nvim-tree-lua nvim-web-devicons
nvim-tree-lua
nvim-web-devicons
];
extraConfigLua = ''
require('nvim-tree').setup(${helpers.toLuaObject options})
'';
};
};
}

View file

@ -1,10 +1,11 @@
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.specs;
cfg = config.plugins.specs;
helpers = import ../helpers.nix { inherit lib; };
in {
options.programs.nixvim.plugins.specs = {
in
{
options.plugins.specs = {
enable = mkEnableOption "Enable specs-nvim";
show_jumps = mkOption {
@ -104,36 +105,36 @@ in {
};
};
config = let
setup = helpers.toLuaObject {
inherit (cfg) show_jumps min_jump;
ignore_filetypes = attrsets.listToAttrs
(lib.lists.map (x: attrsets.nameValuePair x true)
cfg.ignored_filetypes);
ignore_buftypes = attrsets.listToAttrs
(lib.lists.map (x: attrsets.nameValuePair x true)
cfg.ignored_buffertypes);
popup = {
inherit (cfg) blend width;
delay_ms = cfg.delay;
inc_ms = cfg.increment;
fader = helpers.mkRaw (if cfg.fader.builtin == null then
cfg.fader.custom
else
''require("specs").${cfg.fader.builtin}'');
resizer = helpers.mkRaw (if cfg.resizer.builtin == null then
cfg.resizer.custom
else
''require("specs").${cfg.resizer.builtin}'');
config =
let
setup = helpers.toLuaObject {
inherit (cfg) show_jumps min_jump;
ignore_filetypes = attrsets.listToAttrs
(lib.lists.map (x: attrsets.nameValuePair x true)
cfg.ignored_filetypes);
ignore_buftypes = attrsets.listToAttrs
(lib.lists.map (x: attrsets.nameValuePair x true)
cfg.ignored_buffertypes);
popup = {
inherit (cfg) blend width;
delay_ms = cfg.delay;
inc_ms = cfg.increment;
fader = helpers.mkRaw (if cfg.fader.builtin == null then
cfg.fader.custom
else
''require("specs").${cfg.fader.builtin}'');
resizer = helpers.mkRaw (if cfg.resizer.builtin == null then
cfg.resizer.custom
else
''require("specs").${cfg.resizer.builtin}'');
};
};
};
in mkIf cfg.enable {
programs.nixvim = {
in
mkIf cfg.enable {
extraPlugins = [ pkgs.vimPlugins.specs-nvim ];
extraConfigLua = ''
require('specs').setup(${setup})
'';
};
};
}

View file

@ -1,11 +1,12 @@
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.undotree;
cfg = config.plugins.undotree;
helpers = import ../helpers.nix { inherit lib; };
in {
in
{
options = {
programs.nixvim.plugins.undotree = {
plugins.undotree = {
enable = mkEnableOption "Enable undotree";
windowLayout = mkOption {
@ -107,27 +108,25 @@ in {
};
config = mkIf cfg.enable {
programs.nixvim = {
extraPlugins = [ pkgs.vimPlugins.undotree ];
extraPlugins = [ pkgs.vimPlugins.undotree ];
globals = {
undotree_WindowLayout = mkIf (cfg.windowLayout != null) cfg.windowLayout;
undotree_ShortIndicators = mkIf cfg.shortIndicators 1;
undotree_SplitWidth = mkIf (cfg.windowWidth != null) cfg.windowWidth;
undotree_DiffpanelHeight = mkIf (cfg.diffHeight != null) cfg.diffHeight;
undotree_DiffAutoOpen = mkIf (!cfg.autoOpenDiff) 0;
undotree_SetFocusWhenToggle = mkIf cfg.focusOnToggle 1;
undotree_TreeNodeShape = mkIf (cfg.treeNodeShape != null) cfg.treeNodeShape;
undotree_DiffCommand = mkIf (cfg.diffCommand != null) cfg.diffCommand;
undotree_RelativeTimestamp = mkIf (!cfg.relativeTimestamp) 0;
undotree_HighlightChangedText = mkIf (!cfg.highlightChangedText) 0;
undotree_HighlightChangedWithSign = mkIf (!cfg.highlightChangesWithSign) 0;
undotree_HighlightSyntaxAdd = mkIf (cfg.highlightSyntaxAdd != null) cfg.highlightSyntaxAdd;
undotree_HighlightSyntaxChange = mkIf (cfg.highlightSyntaxChange != null) cfg.highlightSyntaxAdd;
undotree_HighlightSyntaxDel = mkIf (cfg.highlightSyntaxDel != null) cfg.highlightSyntaxDel;
undotree_HelpLine = mkIf (!cfg.showHelpLine) 0;
undotree_CursorLine = mkIf (!cfg.showCursorLine) 0;
};
globals = {
undotree_WindowLayout = mkIf (cfg.windowLayout != null) cfg.windowLayout;
undotree_ShortIndicators = mkIf cfg.shortIndicators 1;
undotree_SplitWidth = mkIf (cfg.windowWidth != null) cfg.windowWidth;
undotree_DiffpanelHeight = mkIf (cfg.diffHeight != null) cfg.diffHeight;
undotree_DiffAutoOpen = mkIf (!cfg.autoOpenDiff) 0;
undotree_SetFocusWhenToggle = mkIf cfg.focusOnToggle 1;
undotree_TreeNodeShape = mkIf (cfg.treeNodeShape != null) cfg.treeNodeShape;
undotree_DiffCommand = mkIf (cfg.diffCommand != null) cfg.diffCommand;
undotree_RelativeTimestamp = mkIf (!cfg.relativeTimestamp) 0;
undotree_HighlightChangedText = mkIf (!cfg.highlightChangedText) 0;
undotree_HighlightChangedWithSign = mkIf (!cfg.highlightChangesWithSign) 0;
undotree_HighlightSyntaxAdd = mkIf (cfg.highlightSyntaxAdd != null) cfg.highlightSyntaxAdd;
undotree_HighlightSyntaxChange = mkIf (cfg.highlightSyntaxChange != null) cfg.highlightSyntaxAdd;
undotree_HighlightSyntaxDel = mkIf (cfg.highlightSyntaxDel != null) cfg.highlightSyntaxDel;
undotree_HelpLine = mkIf (!cfg.showHelpLine) 0;
undotree_CursorLine = mkIf (!cfg.showCursorLine) 0;
};
};
}