modules: start breaking down core modules; simplify tree structure

This commit is contained in:
raf 2024-02-17 04:02:15 +03:00
commit 370913e827
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
242 changed files with 178 additions and 124 deletions

View file

@ -8,6 +8,7 @@
inherit (lib) nvim;
inherit (nvim.lua) toLuaObject;
inherit (nvim.vim) valToVim;
inherit (nvim.bool) mkBool;
cfg = config.vim;
@ -20,13 +21,6 @@
EOF
'';
mkBool = value: description:
mkOption {
type = types.bool;
default = value;
inherit description;
};
# Most of the keybindings code is highly inspired by pta2002/nixvim. Thank you!
mapConfigOptions = {
silent =
@ -93,60 +87,8 @@
inherit mode;
})
maps);
mapOption = types.submodule {
options =
mapConfigOptions
// {
action = mkOption {
type = types.str;
description = "The action to execute.";
};
lua = mkOption {
type = types.bool;
description = ''
If true, `action` is considered to be lua code.
Thus, it will not be wrapped in `""`.
'';
default = false;
};
};
};
mapOptions = mode:
mkOption {
description = "Mappings for ${mode} mode";
type = types.attrsOf mapOption;
default = {};
};
in {
options = {
assertions = lib.mkOption {
type = with types; listOf unspecified;
internal = true;
default = [];
example = literalExpression ''
[
{
assertion = false;
message = "you can't enable this for that reason";
}
]
'';
};
warnings = mkOption {
internal = true;
default = [];
type = with types; listOf str;
example = ["The `foo' service is deprecated and will go away soon!"];
description = lib.mdDoc ''
This option allows modules to show warnings to users during
the evaluation of the system configuration.
'';
};
vim = {
viAlias = mkOption {
description = "Enable vi alias";
@ -196,17 +138,19 @@ in {
Note that these are setup after builtin plugins.
'';
example = literalExpression ''
with pkgs.vimPlugins; {
with pkgs.vimPlugins; {
aerial = {
package = aerial-nvim;
setup = "require('aerial').setup {}";
};
harpoon = {
package = harpoon;
setup = "require('harpoon').setup {}";
after = ["aerial"];
};
}'';
}
'';
};
globals = mkOption {
@ -214,40 +158,6 @@ in {
description = "Set containing global variable values";
type = types.attrs;
};
maps = mkOption {
type = types.submodule {
options = {
normal = mapOptions "normal";
insert = mapOptions "insert";
select = mapOptions "select";
visual = mapOptions "visual and select";
terminal = mapOptions "terminal";
normalVisualOp = mapOptions "normal, visual, select and operator-pending (same as plain 'map')";
visualOnly = mapOptions "visual only";
operator = mapOptions "operator-pending";
insertCommand = mapOptions "insert and command-line";
lang = mapOptions "insert, command-line and lang-arg";
command = mapOptions "command-line";
};
};
default = {};
description = ''
Custom keybindings for any mode.
For plain maps (e.g. just 'map' or 'remap') use maps.normalVisualOp.
'';
example = ''
maps = {
normal."<leader>m" = {
silent = true;
action = "<cmd>make<CR>";
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
};
'';
};
};
};

View file

@ -0,0 +1,103 @@
{lib, ...}: let
inherit (lib) mkOption types;
inherit (lib) nvim;
inherit (nvim.bool) mkBool;
# Most of the keybindings code is highly inspired by pta2002/nixvim. Thank you!
mapConfigOptions = {
silent =
mkBool false
"Whether this mapping should be silent. Equivalent to adding <silent> to a map.";
nowait =
mkBool false
"Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
script =
mkBool false
"Equivalent to adding <script> to a map.";
expr =
mkBool false
"Means that the action is actually an expression. Equivalent to adding <expr> to a map.";
unique =
mkBool false
"Whether to fail if the map is already defined. Equivalent to adding <unique> to a map.";
noremap =
mkBool true
"Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
desc = mkOption {
type = types.nullOr types.str;
default = null;
description = "A description of this keybind, to be shown in which-key, if you have it enabled.";
};
};
mapOption = types.submodule {
options =
mapConfigOptions
// {
action = mkOption {
type = types.str;
description = "The action to execute.";
};
lua = mkOption {
type = types.bool;
description = ''
If true, `action` is considered to be lua code.
Thus, it will not be wrapped in `""`.
'';
default = false;
};
};
};
mapOptions = mode:
mkOption {
description = "Mappings for ${mode} mode";
type = types.attrsOf mapOption;
default = {};
};
in {
options = {
vim = {
maps = mkOption {
type = types.submodule {
options = {
normal = mapOptions "normal";
insert = mapOptions "insert";
select = mapOptions "select";
visual = mapOptions "visual and select";
terminal = mapOptions "terminal";
normalVisualOp = mapOptions "normal, visual, select and operator-pending (same as plain 'map')";
visualOnly = mapOptions "visual only";
operator = mapOptions "operator-pending";
insertCommand = mapOptions "insert and command-line";
lang = mapOptions "insert, command-line and lang-arg";
command = mapOptions "command-line";
};
};
default = {};
description = ''
Custom keybindings for any mode.
For plain maps (e.g. just 'map' or 'remap') use maps.normalVisualOp.
'';
example = ''
maps = {
normal."<leader>m" = {
silent = true;
action = "<cmd>make<CR>";
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
};
'';
};
};
};
}

View file

@ -0,0 +1,31 @@
{lib, ...}: let
inherit (lib) types;
inherit (lib.options) mkOption literalExpression;
in {
options = {
assertions = mkOption {
type = with types; listOf unspecified;
internal = true;
default = [];
example = literalExpression ''
[
{
assertion = false;
message = "you can't enable this for that reason";
}
]
'';
};
warnings = mkOption {
internal = true;
default = [];
type = with types; listOf str;
example = ["The `foo' service is deprecated and will go away soon!"];
description = ''
This option allows modules to show warnings to users during
the evaluation of the system configuration.
'';
};
};
}

View file

@ -3,33 +3,43 @@
lib,
check ? true,
}: let
inherit (lib) mkDefault;
plugins = builtins.map (p: ./plugins + "/${p}") [
"completion"
"theme"
"statusline"
"tabline"
"filetree"
"visuals"
"lsp"
"treesitter"
"autopairs"
"snippets"
"git"
"minimap"
"dashboard"
"utility"
"rich-presence"
"notes"
"terminal"
"ui"
"assistant"
"session"
"comments"
"projects"
"languages"
"debugger"
];
core = builtins.map (p: ./core + "/${p}") [
"build"
"mappings"
"warnings"
];
modules = [
./completion
./theme
./core
./basic
./statusline
./tabline
./filetree
./visuals
./lsp
./treesitter
./autopairs
./snippets
./git
./minimap
./dashboard
./utility
./rich-presence
./notes
./terminal
./ui
./assistant
./session
./comments
./projects
./languages
./debugger
./neovim
];
pkgsModule = {config, ...}: {
@ -38,11 +48,11 @@
inherit check;
args = {
baseModules = modules;
pkgsPath = lib.mkDefault pkgs.path;
pkgs = lib.mkDefault pkgs;
pkgsPath = mkDefault pkgs.path;
pkgs = mkDefault pkgs;
};
};
};
};
in
modules ++ [pkgsModule]
[pkgsModule] ++ (lib.concatLists [core modules plugins])

Some files were not shown because too many files have changed in this diff Show more