This commit is contained in:
Alfarel 2025-11-06 15:02:17 +07:00 committed by GitHub
commit 6ab6ce6d73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 91 additions and 111 deletions

View file

@ -4,16 +4,8 @@
flake-parts, flake-parts,
self, self,
... ...
} @ inputs: let } @ inputs:
# Call the extended library with `inputs`. flake-parts.lib.mkFlake {inherit inputs;} {
# inputs is used to get the original standard library, and to pass inputs
# to the plugin autodiscovery function
lib = import ./lib/stdlib-extended.nix {inherit inputs self;};
in
flake-parts.lib.mkFlake {
inherit inputs;
specialArgs = {inherit lib;};
} {
# Allow users to bring their own systems. # Allow users to bring their own systems.
# «https://github.com/nix-systems/nix-systems» # «https://github.com/nix-systems/nix-systems»
systems = import inputs.systems; systems = import inputs.systems;
@ -24,16 +16,19 @@
./flake/develop.nix ./flake/develop.nix
]; ];
flake = { flake = {lib, ...}: let
# inputs is passed for the plugin autodiscovery function
nvf-lib = lib.fixedPoints.makeExtensible (import ./lib {inherit inputs self;});
in {
lib = { lib = {
inherit (lib) nvim; nvim = nvf-lib;
inherit (lib.nvim) neovimConfiguration; inherit (nvf-lib) neovimConfiguration;
}; };
inherit (lib.importJSON ./npins/sources.json) pins; inherit (lib.importJSON ./npins/sources.json) pins;
homeManagerModules = { homeManagerModules = {
nvf = import ./flake/modules/home-manager.nix {inherit lib inputs;}; nvf = import ./flake/modules/home-manager.nix {inherit inputs;};
default = self.homeManagerModules.nvf; default = self.homeManagerModules.nvf;
neovim-flake = neovim-flake =
lib.warn '' lib.warn ''
@ -44,7 +39,7 @@
}; };
nixosModules = { nixosModules = {
nvf = import ./flake/modules/nixos.nix {inherit lib inputs;}; nvf = import ./flake/modules/nixos.nix {inherit inputs;};
default = self.nixosModules.nvf; default = self.nixosModules.nvf;
neovim-flake = neovim-flake =
lib.warn '' lib.warn ''

View file

@ -1,4 +1,4 @@
{lib, ...}: { {self, ...}: {
perSystem = { perSystem = {
pkgs, pkgs,
config, config,
@ -20,7 +20,7 @@
packages.dev = let packages.dev = let
configuration = {}; configuration = {};
customNeovim = lib.nvim.neovimConfiguration { customNeovim = self.lib.nvim.neovimConfiguration {
inherit pkgs; inherit pkgs;
modules = [configuration]; modules = [configuration];
}; };

View file

@ -1,9 +1,7 @@
# Home Manager module # Home Manager module
{ {inputs}: {
inputs,
lib,
}: {
config, config,
lib,
pkgs, pkgs,
... ...
}: let }: let

View file

@ -1,9 +1,7 @@
# NixOS module # NixOS module
{ {inputs}: {
inputs,
lib,
}: {
config, config,
lib,
pkgs, pkgs,
... ...
}: let }: let

View file

@ -1,4 +1,4 @@
{lib}: let _: let
inherit (builtins) listToAttrs; inherit (builtins) listToAttrs;
in { in {
mapListToAttrs = f: list: listToAttrs (map f list); mapListToAttrs = f: list: listToAttrs (map f list);

View file

@ -1,4 +1,4 @@
{lib}: let {lib, ...}: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.modules) mkIf mkDefault; inherit (lib.modules) mkIf mkDefault;
inherit (lib.types) nullOr str; inherit (lib.types) nullOr str;

View file

@ -1,4 +1,4 @@
{lib}: let {lib, ...}: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.types) bool; inherit (lib.types) bool;
inherit (lib.modules) mkRenamedOptionModule; inherit (lib.modules) mkRenamedOptionModule;

View file

@ -7,11 +7,15 @@
# #
# - the addition of the function `entryBefore` indicating a "wanted # - the addition of the function `entryBefore` indicating a "wanted
# by" relationship. # by" relationship.
{lib}: let {
lib,
nvf-lib,
...
}: let
inherit (builtins) isAttrs attrValues attrNames elem all head tail length toJSON isString removeAttrs; inherit (builtins) isAttrs attrValues attrNames elem all head tail length toJSON isString removeAttrs;
inherit (lib.attrsets) filterAttrs mapAttrs; inherit (lib.attrsets) filterAttrs mapAttrs;
inherit (lib.lists) toposort; inherit (lib.lists) toposort;
inherit (lib.nvim.dag) empty isEntry entryBetween entryAfter entriesBetween entryAnywhere topoSort; inherit (nvf-lib.dag) empty isEntry entryBetween entryAfter entriesBetween entryAnywhere topoSort;
in { in {
empty = {}; empty = {};

View file

@ -1,16 +1,22 @@
{ {
self,
inputs, inputs,
lib, self,
... }: final: let
}: { # Modeled after nixpkgs' lib.
types = import ./types {inherit lib self;}; callLibs = file:
config = import ./config.nix {inherit lib;}; import file {
binds = import ./binds.nix {inherit lib;}; nvf-lib = final;
dag = import ./dag.nix {inherit lib;}; inherit inputs self;
languages = import ./languages.nix {inherit lib;}; inherit (inputs.nixpkgs) lib;
lists = import ./lists.nix {inherit lib;}; };
attrsets = import ./attrsets.nix {inherit lib;}; in {
lua = import ./lua.nix {inherit lib;}; types = callLibs ./types;
neovimConfiguration = import ../modules {inherit self inputs lib;}; config = callLibs ./config.nix;
binds = callLibs ./binds.nix;
dag = callLibs ./dag.nix;
languages = callLibs ./languages.nix;
lists = callLibs ./lists.nix;
attrsets = callLibs ./attrsets.nix;
lua = callLibs ./lua.nix;
neovimConfiguration = callLibs ../modules;
} }

View file

@ -1,9 +1,13 @@
{lib}: let {
lib,
nvf-lib,
...
}: let
inherit (builtins) isString getAttr; inherit (builtins) isString getAttr;
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.types) listOf bool str submodule attrsOf anything either nullOr uniq; inherit (lib.types) listOf bool str submodule attrsOf anything either nullOr uniq;
inherit (lib.nvim.attrsets) mapListToAttrs; inherit (nvf-lib.attrsets) mapListToAttrs;
inherit (lib.nvim.types) luaInline; inherit (nvf-lib.types) luaInline;
in { in {
# TODO: remove # TODO: remove
diagnosticsToLua = { diagnosticsToLua = {

View file

@ -1,4 +1,4 @@
{lib}: let {lib, ...}: let
inherit (lib.lists) elem all; inherit (lib.lists) elem all;
in { in {
/* /*

View file

@ -1,5 +1,5 @@
# Helpers for converting values to lua # Helpers for converting values to lua
{lib}: let {lib, ...}: let
isLuaInline = object: (object._type or null) == "lua-inline"; isLuaInline = object: (object._type or null) == "lua-inline";
toLuaObject = args: toLuaObject = args:

View file

@ -1,21 +0,0 @@
# Convenience function that returns the given Nixpkgs standard library
# extended with our functions using `lib.extend`.
{inputs, ...} @ args:
inputs.nixpkgs.lib.extend (self: super: {
# WARNING: New functions should not be added here, but to files
# imported by `./default.nix` under their own categories. If your
# function does not fit to any of the existing categories, create
# a new file and import it in `./default.nix.`
# Makes our custom functions available under `lib.nvim` where stdlib-extended.nix is imported
# with the appropriate arguments. For end-users, a `lib` output will be accessible from the flake.
# E.g. for an input called `nvf`, `inputs.nvf.lib.nvim` will return the set
# below.
nvim = import ./. {
inherit (args) inputs self;
lib = self;
};
# For forward compatibility.
literalExpression = super.literalExpression or super.literalExample;
})

View file

@ -1,4 +1,4 @@
{lib}: let {lib, ...}: let
inherit (lib.options) mergeEqualOption; inherit (lib.options) mergeEqualOption;
inherit (lib.lists) singleton; inherit (lib.lists) singleton;
inherit (lib.strings) isString stringLength match; inherit (lib.strings) isString stringLength match;

View file

@ -1,33 +1,31 @@
# From home-manager: https://github.com/nix-community/home-manager/blob/master/modules/lib/types-dag.nix # From home-manager: https://github.com/nix-community/home-manager/blob/master/modules/lib/types-dag.nix
# Used for ordering configuration text. # Used for ordering configuration text.
{lib}: let {
inherit lib,
(lib) nvf-lib,
defaultFunctor ...
nvim }: let
mkIf inherit (lib.types) attrsOf defaultFunctor listOf mkOptionType str submodule;
mkOrder inherit (lib.modules) mkIf mkOrder;
mkOption inherit (lib.options) mkOption;
mkOptionType inherit (nvf-lib.dag) isEntry entryAnywhere;
types
;
dagEntryOf = elemType: let dagEntryOf = elemType: let
submoduleType = types.submodule ({name, ...}: { submoduleType = submodule ({name, ...}: {
options = { options = {
data = mkOption {type = elemType;}; data = mkOption {type = elemType;};
after = mkOption {type = with types; listOf str;}; after = mkOption {type = listOf str;};
before = mkOption {type = with types; listOf str;}; before = mkOption {type = listOf str;};
}; };
config = mkIf (elemType.name == "submodule") { config = mkIf (elemType.name == "submodule") {
data._module.args.dagName = name; data._module.args.dagName = name;
}; };
}); });
maybeConvert = def: maybeConvert = def:
if nvim.dag.isEntry def.value if isEntry def.value
then def.value then def.value
else else
nvim.dag.entryAnywhere ( entryAnywhere (
if def ? priority if def ? priority
then mkOrder def.priority def.value then mkOrder def.priority def.value
else def.value else def.value
@ -53,7 +51,7 @@ in rec {
# "actual" attribute name a new submodule argument is provided with # "actual" attribute name a new submodule argument is provided with
# the name `dagName`. # the name `dagName`.
dagOf = elemType: let dagOf = elemType: let
attrEquivalent = types.attrsOf (dagEntryOf elemType); attrEquivalent = attrsOf (dagEntryOf elemType);
in in
mkOptionType rec { mkOptionType rec {
name = "dagOf"; name = "dagOf";

View file

@ -1,14 +1,6 @@
{ args: {
lib, inherit (import ./dag.nix args) dagOf;
self, inherit (import ./plugins.nix args) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType;
}: let inherit (import ./languages.nix args) diagnostics mkGrammarOption;
typesDag = import ./dag.nix {inherit lib;}; inherit (import ./custom.nix args) char hexColor mergelessListOf singleOrListOf;
typesPlugin = import ./plugins.nix {inherit lib self;};
typesLanguage = import ./languages.nix {inherit lib;};
customTypes = import ./custom.nix {inherit lib;};
in {
inherit (typesDag) dagOf;
inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType;
inherit (typesLanguage) diagnostics mkGrammarOption;
inherit (customTypes) char hexColor mergelessListOf singleOrListOf;
} }

View file

@ -1,4 +1,4 @@
{lib}: let {lib, ...}: let
inherit (lib.options) mkOption mkPackageOption; inherit (lib.options) mkOption mkPackageOption;
inherit (lib.attrsets) attrNames; inherit (lib.attrsets) attrNames;
inherit (lib.types) listOf either enum submodule package; inherit (lib.types) listOf either enum submodule package;

View file

@ -1,11 +1,14 @@
{ {
lib, lib,
nvf-lib,
self, self,
...
}: let }: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair; inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair;
inherit (lib.strings) hasPrefix removePrefix; inherit (lib.strings) hasPrefix removePrefix;
inherit (lib.types) submodule either package enum str lines anything listOf nullOr; inherit (lib.types) submodule either package enum str lines anything listOf nullOr mkOptionType;
inherit (nvf-lib.lua) isLuaInline;
# Get the names of all flake inputs that start with the given prefix. # Get the names of all flake inputs that start with the given prefix.
fromInputs = { fromInputs = {
@ -64,9 +67,9 @@ in {
type = pluginsType; type = pluginsType;
}; };
luaInline = lib.mkOptionType { luaInline = mkOptionType {
name = "luaInline"; name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x; check = x: isLuaInline x;
}; };
/* /*

View file

@ -1,7 +1,7 @@
{ {
self, self,
inputs, inputs,
lib, ...
}: { }: {
pkgs, pkgs,
extraSpecialArgs ? {}, extraSpecialArgs ? {},
@ -10,17 +10,20 @@
extraModules ? [], extraModules ? [],
configuration ? {}, configuration ? {},
}: let }: let
inherit (pkgs) lib;
inherit (lib.modules) evalModules;
inherit (lib.strings) toString; inherit (lib.strings) toString;
inherit (lib.lists) concatLists; inherit (lib.trivial) warn;
inherit (lib.lists) concatLists optional optionals;
# import modules.nix with `check`, `pkgs` and `lib` as arguments # import modules.nix with `check` and `pkgs` as arguments
# check can be disabled while calling this file is called # check can be disabled while calling this file is called
# to avoid checking in all modules # to avoid checking in all modules
nvimModules = import ./modules.nix {inherit pkgs lib;}; nvimModules = import ./modules.nix {inherit pkgs;};
# evaluate the extended library with the modules # evaluate the extended library with the modules
# optionally with any additional modules passed by the user # optionally with any additional modules passed by the user
module = lib.evalModules { module = evalModules {
specialArgs = specialArgs =
extraSpecialArgs extraSpecialArgs
// { // {
@ -30,12 +33,12 @@
modules = concatLists [ modules = concatLists [
nvimModules nvimModules
modules modules
(lib.optional (configuration != {}) (lib.warn '' (optional (configuration != {}) (warn ''
nvf: passing 'configuration' to lib.neovimConfiguration is deprecated. nvf: passing 'configuration' to lib.neovimConfiguration is deprecated.
'' ''
configuration)) configuration))
(lib.optionals (extraModules != []) (lib.warn '' (optionals (extraModules != []) (warn ''
nvf: passing 'extraModules' to lib.neovimConfiguration is deprecated, use 'modules' instead. nvf: passing 'extraModules' to lib.neovimConfiguration is deprecated, use 'modules' instead.
'' ''
extraModules)) extraModules))