refactor: init module has simler configuration

dev
LeMarsu 2026-03-11 21:48:36 +01:00
parent 2816b256d4
commit c00555d6d8
2 changed files with 29 additions and 25 deletions

View File

@ -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: {

View File

@ -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;
};