mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-22 13:20:44 +00:00
modules/core: move mkSection functions to lib/dag
This commit is contained in:
parent
b4384a833f
commit
cb362a7905
2 changed files with 19 additions and 18 deletions
10
lib/dag.nix
10
lib/dag.nix
|
@ -107,4 +107,14 @@ in {
|
||||||
|
|
||||||
entryAfter = entryBetween [];
|
entryAfter = entryBetween [];
|
||||||
entryBefore = before: entryBetween before [];
|
entryBefore = before: entryBetween before [];
|
||||||
|
|
||||||
|
mkLuarcSection = section: ''
|
||||||
|
-- SECTION: ${section.name}
|
||||||
|
${section.data}
|
||||||
|
'';
|
||||||
|
|
||||||
|
mkVimrcSection = section: ''
|
||||||
|
" SECTION: ${section.name}
|
||||||
|
${section.data}
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
inherit (lib.trivial) showWarnings;
|
inherit (lib.trivial) showWarnings;
|
||||||
inherit (lib.types) bool str oneOf attrsOf nullOr attrs submodule lines;
|
inherit (lib.types) bool str oneOf attrsOf nullOr attrs submodule lines;
|
||||||
inherit (lib.nvim.types) dagOf;
|
inherit (lib.nvim.types) dagOf;
|
||||||
inherit (lib.nvim.dag) entryAnywhere entryAfter topoSort;
|
|
||||||
inherit (lib.generators) mkLuaInline;
|
inherit (lib.generators) mkLuaInline;
|
||||||
|
inherit (lib.nvim.dag) entryAnywhere entryAfter topoSort mkLuarcSection mkVimrcSection;
|
||||||
inherit (lib.nvim.lua) toLuaObject;
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
inherit (lib.nvim.vim) valToVim;
|
inherit (lib.nvim.vim) valToVim;
|
||||||
inherit (lib.nvim.config) mkBool;
|
inherit (lib.nvim.config) mkBool;
|
||||||
|
@ -21,14 +21,13 @@
|
||||||
|
|
||||||
wrapLuaConfig = luaConfig: ''
|
wrapLuaConfig = luaConfig: ''
|
||||||
lua << EOF
|
lua << EOF
|
||||||
${optionalString cfg.enableLuaLoader ''
|
${optionalString cfg.enableLuaLoader "vim.loader.enable()"}
|
||||||
vim.loader.enable()
|
|
||||||
''}
|
|
||||||
${luaConfig}
|
${luaConfig}
|
||||||
EOF
|
EOF
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Most of the keybindings code is highly inspired by pta2002/nixvim. Thank you!
|
# Most of the keybindings code is highly inspired by pta2002/nixvim.
|
||||||
|
# Thank you!
|
||||||
mapConfigOptions = {
|
mapConfigOptions = {
|
||||||
silent =
|
silent =
|
||||||
mkBool false
|
mkBool false
|
||||||
|
@ -230,11 +229,6 @@ in {
|
||||||
else abort ("Dependency cycle in ${name}: " + toJSON sortedDag);
|
else abort ("Dependency cycle in ${name}: " + toJSON sortedDag);
|
||||||
in
|
in
|
||||||
result;
|
result;
|
||||||
|
|
||||||
mkSection = r: ''
|
|
||||||
-- SECTION: ${r.name}
|
|
||||||
${r.data}
|
|
||||||
'';
|
|
||||||
in {
|
in {
|
||||||
vim = {
|
vim = {
|
||||||
startPlugins = map (x: x.package) (attrValues cfg.extraPlugins);
|
startPlugins = map (x: x.package) (attrValues cfg.extraPlugins);
|
||||||
|
@ -242,7 +236,7 @@ in {
|
||||||
globalsScript = entryAnywhere (concatStringsSep "\n" globalsScript);
|
globalsScript = entryAnywhere (concatStringsSep "\n" globalsScript);
|
||||||
|
|
||||||
luaScript = let
|
luaScript = let
|
||||||
mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkSection r)));
|
mapResult = result: (wrapLuaConfig (concatStringsSep "\n" (map mkLuarcSection result)));
|
||||||
luaConfig = resolveDag {
|
luaConfig = resolveDag {
|
||||||
name = "lua config script";
|
name = "lua config script";
|
||||||
dag = cfg.luaConfigRC;
|
dag = cfg.luaConfigRC;
|
||||||
|
@ -252,7 +246,7 @@ in {
|
||||||
entryAfter ["globalsScript"] luaConfig;
|
entryAfter ["globalsScript"] luaConfig;
|
||||||
|
|
||||||
extraPluginConfigs = let
|
extraPluginConfigs = let
|
||||||
mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkSection r)));
|
mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkLuarcSection r)));
|
||||||
extraPluginsDag = mapAttrs (_: {
|
extraPluginsDag = mapAttrs (_: {
|
||||||
after,
|
after,
|
||||||
setup,
|
setup,
|
||||||
|
@ -289,18 +283,15 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
builtConfigRC = let
|
builtConfigRC = let
|
||||||
|
# Catch assertions and warnings
|
||||||
|
# and throw for each failed assertion. If no assertions are found, show warnings.
|
||||||
failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
|
failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
|
||||||
|
|
||||||
baseSystemAssertWarn =
|
baseSystemAssertWarn =
|
||||||
if failedAssertions != []
|
if failedAssertions != []
|
||||||
then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
||||||
else showWarnings config.warnings;
|
else showWarnings config.warnings;
|
||||||
|
|
||||||
mkSection = r: ''
|
mapResult = result: (concatStringsSep "\n" (map mkVimrcSection result));
|
||||||
" SECTION: ${r.name}
|
|
||||||
${r.data}
|
|
||||||
'';
|
|
||||||
mapResult = r: (concatStringsSep "\n" (map mkSection r));
|
|
||||||
vimConfig = resolveDag {
|
vimConfig = resolveDag {
|
||||||
name = "vim config script";
|
name = "vim config script";
|
||||||
dag = cfg.configRC;
|
dag = cfg.configRC;
|
||||||
|
|
Loading…
Reference in a new issue