1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-21 17:59:41 +01:00
nixvim/lib/top-level.nix
Matt Sturgeon c53e0161c3 lib: simplify bootstrapping
Previously, `lib/top-level.nix` used an `_isExtended` flag to indicate
whether the provided `lib` was already extended. This made bootstrapping
unclear and introduced the possibility of circular construction.

All construction now flows through the lib-overlay, removing
`_isExtended`. As a result, `lib/top-level.nix` always receives the
final extended lib.

The `<flake>.lib.nixvim` output is now defined as:

    (lib.extend <nixvim>.lib.overlay).nixvim

The overlay now imports `top-level.nix` directly, making it the
canonical entrypoint for constructing Nixvim's section of the lib.

A clarifying doccomment was added to `lib/top-level.nix`.
2025-11-20 20:57:10 +00:00

161 lines
3.6 KiB
Nix

/**
Construct Nixvim's section of the lib: `lib.nixvim`.
This function requires the final extended lib (as produced by `./overlay.nix`)
and should not usually be imported directly.
The flake output `<nixvim>.lib.nixvim` provides an instance of Nixvim's lib section.
# Inputs
`flake`
: The nixvim flake.
`lib`
: The final extended lib.
*/
{
lib,
flake,
}:
lib.makeExtensible (
self:
let
# Used when importing parts of our lib
call = lib.callPackageWith {
inherit
call
self
lib
;
};
in
{
autocmd = call ./autocmd-helpers.nix { };
builders = call ./builders.nix { };
deprecation = call ./deprecation.nix { };
keymaps = call ./keymap-helpers.nix { };
lua = call ./to-lua.nix { };
lua-types = call ./lua-types.nix { };
modules = call ./modules.nix { inherit flake; };
options = call ./options.nix { };
plugins = call ./plugins { };
utils = call ./utils.nix { } // call ./utils.internal.nix { };
# Top-level helper aliases:
# TODO: deprecate some aliases
inherit (self.builders)
writeLua
writeByteCompiledLua
byteCompileLuaFile
byteCompileLuaHook
byteCompileLuaDrv
;
inherit (self.deprecation)
getOptionRecursive
mkDeprecatedSubOptionModule
mkRemovedPackageOptionModule
mkSettingsRenamedOptionModules
transitionType
;
inherit (self.modules)
evalNixvim
;
inherit (self.options)
defaultNullOpts
mkAutoLoadOption
mkCompositeOption
mkCompositeOption'
mkLazyLoadOption
mkMaybeUnpackagedOption
mkNullOrLua
mkNullOrLua'
mkNullOrLuaFn
mkNullOrLuaFn'
mkNullOrOption
mkNullOrOption'
mkNullOrStr
mkNullOrStr'
mkNullOrStrLuaFnOr
mkNullOrStrLuaFnOr'
mkNullOrStrLuaOr
mkNullOrStrLuaOr'
mkPackageOption
mkPluginPackageOption
mkSettingsOption
mkUnpackagedOption
pluginDefaultText
;
inherit (self.utils)
applyPrefixToAttrs
concatNonEmptyLines
emptyTable
enableExceptInTests
groupListBySize
hasContent
ifNonNull'
listToUnkeyedAttrs
literalLua
mkAssertions
mkIfNonNull
mkIfNonNull'
mkRaw
mkRawKey
mkWarnings
nestedLiteral
nestedLiteralLua
override
overrideDerivation
toRawKeys
toSnakeCase
upperFirstChar
wrapDo
wrapLuaForVimscript
wrapVimscriptForLua
;
inherit (self.lua) toLuaObject;
mkLuaInline = self.lua.mkInline;
# TODO: Removed 2024-12-21
extendedLib = throw "`extendedLib` has been removed. Use `lib.extend <nixvim>.lib.overlay` instead.";
}
//
# TODO: Removed 2024-09-27; remove after 24.11
lib.mapAttrs
(
old: new:
throw "The `${old}` alias has been removed. Use `${new}` on a lib with nixvim's extensions."
)
{
maintainers = "lib.maintainers";
nixvimTypes = "lib.types";
}
//
# TODO: neovim-plugin & vim-plugin aliases deprecated 2024-12-22; internal functions
lib.mapAttrs'
(scope: names: {
name = "${scope}-plugin";
value = lib.genAttrs names (
name:
lib.warn "`${scope}-plugin.${name}` has been moved to `plugins.${scope}.${name}`."
self.plugins.${scope}.${name}
);
})
{
neovim = [
"extraOptionsOptions"
"mkNeovimPlugin"
];
vim = [
"mkSettingsOption"
"mkSettingsOptionDescription"
"mkVimPlugin"
];
}
)