diff --git a/lib/modules/default.nix b/lib/modules/default.nix index 29221e9..b631b2c 100644 --- a/lib/modules/default.nix +++ b/lib/modules/default.nix @@ -51,19 +51,17 @@ in { }: let pkg = pkgs.wrapNeovimUnstable config.package config.neovimOptions; - customLuaRC = modules.init.mkCustomLuaRc config.init; - - plugins = concatLists [ - (map modules.plugin.extract config.plugins) - (optional (! isNull config.runtime) config.runtime.package) - [config.slothPlugin] - ]; - - neovimOptions = pkgs.neovimUtils.makeNeovimConfig { + neovimOptions = pkgs.neovimUtils.makeNeovimConfig rec { inherit (config) extraLuaPackages viAlias vimAlias; - inherit customLuaRC plugins; + + customLuaRC = config.init.finalContent; wrapRc = customLuaRC != null; - # inherit customRC; + + plugins = concatLists [ + (map modules.plugin.extract config.plugins) + (optional (! isNull config.runtime) config.runtime.package) + [config.slothPlugin] + ]; }; neovimPackage = pkg.overrideAttrs (final: super: { diff --git a/lib/modules/init.nix b/lib/modules/init.nix index 848b787..da255a2 100644 --- a/lib/modules/init.nix +++ b/lib/modules/init.nix @@ -4,18 +4,15 @@ ... }: let inherit (builtins) isAttrs isPath isString readFile; - inherit - (pkgs.lib) - fileContents - fix - mkOption - optionalAttrs - optionalString - types - ; + inherit (pkgs.lib) fileContents fix mkOption optionalAttrs optionalString types; lua = callModule ../lua.nix {}; + coerceToModule = value: + if isAttrs value + then value + else {finalContent = textOrContent value;}; + textOrContent = content: if isPath content then fileContents content @@ -25,6 +22,7 @@ init ? null, postInit ? null, config ? null, + ... }: let initStr = optionalString (! isNull init) '' (function() @@ -34,10 +32,10 @@ ''; postInitContent = optionalAttrs (! isNull postInit) { - post_init = lua.lambda [] (textOrContent (lua.raw postInit)); + post_init = lua.lambda [] (lua.raw (textOrContent postInit)); }; - slothCall = "require('sloth-flake').setup ${lua.renderLua {} postInitContent}"; + slothCall = "require('sloth-flake').setup ${lua.renderLua {} postInitContent};"; configStr = optionalString (! isNull config) '' @@ -53,7 +51,7 @@ ''; in fix (self: { - module = types.submodule { + module = types.submodule ({config, ...}: { options = { init = mkOption { type = with types; nullOr (either path str); @@ -78,15 +76,23 @@ in Lua code called after all plugins are loaded ''; }; + + finalContent = mkOption { + type = with types; nullOr str; + default = self.mkCustomLuaRc config; + description = '' + The resulted init package. + ''; + }; }; - }; + }); option = mkOption { default = null; description = '' init.lua configuration ''; - type = with types; nullOr (oneOf [path str self.module]); + type = with types; coercedTo (nullOr (oneOf [path str])) coerceToModule self.module; example = ./init.lua; };