diff --git a/flake.nix b/flake.nix index 35820e0b..83b85a96 100644 --- a/flake.nix +++ b/flake.nix @@ -4,16 +4,8 @@ flake-parts, self, ... - } @ inputs: let - # Call the extended library with `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;}; - } { + } @ inputs: + flake-parts.lib.mkFlake {inherit inputs;} { # Allow users to bring their own systems. # «https://github.com/nix-systems/nix-systems» systems = import inputs.systems; @@ -24,16 +16,19 @@ ./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 = { - inherit (lib) nvim; - inherit (lib.nvim) neovimConfiguration; + nvim = nvf-lib; + inherit (nvf-lib) neovimConfiguration; }; inherit (lib.importJSON ./npins/sources.json) pins; homeManagerModules = { - nvf = import ./flake/modules/home-manager.nix {inherit lib inputs;}; + nvf = import ./flake/modules/home-manager.nix {inherit inputs;}; default = self.homeManagerModules.nvf; neovim-flake = lib.warn '' @@ -44,7 +39,7 @@ }; nixosModules = { - nvf = import ./flake/modules/nixos.nix {inherit lib inputs;}; + nvf = import ./flake/modules/nixos.nix {inherit inputs;}; default = self.nixosModules.nvf; neovim-flake = lib.warn '' diff --git a/flake/develop.nix b/flake/develop.nix index 71c13688..1034b5d8 100644 --- a/flake/develop.nix +++ b/flake/develop.nix @@ -1,4 +1,4 @@ -{lib, ...}: { +{self, ...}: { perSystem = { pkgs, config, @@ -20,7 +20,7 @@ packages.dev = let configuration = {}; - customNeovim = lib.nvim.neovimConfiguration { + customNeovim = self.lib.nvim.neovimConfiguration { inherit pkgs; modules = [configuration]; }; diff --git a/flake/modules/home-manager.nix b/flake/modules/home-manager.nix index f305558b..348c4d6c 100644 --- a/flake/modules/home-manager.nix +++ b/flake/modules/home-manager.nix @@ -1,9 +1,7 @@ # Home Manager module -{ - inputs, - lib, -}: { +{inputs}: { config, + lib, pkgs, ... }: let diff --git a/flake/modules/nixos.nix b/flake/modules/nixos.nix index 8f95a12a..409bbe59 100644 --- a/flake/modules/nixos.nix +++ b/flake/modules/nixos.nix @@ -1,9 +1,7 @@ # NixOS module -{ - inputs, - lib, -}: { +{inputs}: { config, + lib, pkgs, ... }: let diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 59275af9..4127edba 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -1,4 +1,4 @@ -{lib}: let +_: let inherit (builtins) listToAttrs; in { mapListToAttrs = f: list: listToAttrs (map f list); diff --git a/lib/binds.nix b/lib/binds.nix index bb40a89e..3eecf84e 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -1,4 +1,4 @@ -{lib}: let +{lib, ...}: let inherit (lib.options) mkOption; inherit (lib.modules) mkIf mkDefault; inherit (lib.types) nullOr str; diff --git a/lib/config.nix b/lib/config.nix index 40d81578..0d11ffc3 100644 --- a/lib/config.nix +++ b/lib/config.nix @@ -1,4 +1,4 @@ -{lib}: let +{lib, ...}: let inherit (lib.options) mkOption; inherit (lib.types) bool; inherit (lib.modules) mkRenamedOptionModule; diff --git a/lib/dag.nix b/lib/dag.nix index db5d53b7..85b485dd 100644 --- a/lib/dag.nix +++ b/lib/dag.nix @@ -7,11 +7,15 @@ # # - the addition of the function `entryBefore` indicating a "wanted # by" relationship. -{lib}: let +{ + lib, + nvf-lib, + ... +}: let inherit (builtins) isAttrs attrValues attrNames elem all head tail length toJSON isString removeAttrs; inherit (lib.attrsets) filterAttrs mapAttrs; 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 { empty = {}; diff --git a/lib/default.nix b/lib/default.nix index c4388e82..5623c956 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,16 +1,22 @@ { - self, inputs, - lib, - ... -}: { - types = import ./types {inherit lib self;}; - config = import ./config.nix {inherit lib;}; - binds = import ./binds.nix {inherit lib;}; - dag = import ./dag.nix {inherit lib;}; - languages = import ./languages.nix {inherit lib;}; - lists = import ./lists.nix {inherit lib;}; - attrsets = import ./attrsets.nix {inherit lib;}; - lua = import ./lua.nix {inherit lib;}; - neovimConfiguration = import ../modules {inherit self inputs lib;}; + self, +}: final: let + # Modeled after nixpkgs' lib. + callLibs = file: + import file { + nvf-lib = final; + inherit inputs self; + inherit (inputs.nixpkgs) lib; + }; +in { + types = callLibs ./types; + 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; } diff --git a/lib/languages.nix b/lib/languages.nix index 899d9ea8..f3d6f5a1 100644 --- a/lib/languages.nix +++ b/lib/languages.nix @@ -1,9 +1,13 @@ -{lib}: let +{ + lib, + nvf-lib, + ... +}: let inherit (builtins) isString getAttr; inherit (lib.options) mkOption; inherit (lib.types) listOf bool str submodule attrsOf anything either nullOr uniq; - inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.nvim.types) luaInline; + inherit (nvf-lib.attrsets) mapListToAttrs; + inherit (nvf-lib.types) luaInline; in { # TODO: remove diagnosticsToLua = { diff --git a/lib/lists.nix b/lib/lists.nix index 25e85ad2..15b819f8 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -1,4 +1,4 @@ -{lib}: let +{lib, ...}: let inherit (lib.lists) elem all; in { /* diff --git a/lib/lua.nix b/lib/lua.nix index bf879031..30661c3e 100644 --- a/lib/lua.nix +++ b/lib/lua.nix @@ -1,5 +1,5 @@ # Helpers for converting values to lua -{lib}: let +{lib, ...}: let isLuaInline = object: (object._type or null) == "lua-inline"; toLuaObject = args: diff --git a/lib/stdlib-extended.nix b/lib/stdlib-extended.nix deleted file mode 100644 index 403c7b28..00000000 --- a/lib/stdlib-extended.nix +++ /dev/null @@ -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; -}) diff --git a/lib/types/custom.nix b/lib/types/custom.nix index ae509f59..2919e02a 100644 --- a/lib/types/custom.nix +++ b/lib/types/custom.nix @@ -1,4 +1,4 @@ -{lib}: let +{lib, ...}: let inherit (lib.options) mergeEqualOption; inherit (lib.lists) singleton; inherit (lib.strings) isString stringLength match; diff --git a/lib/types/dag.nix b/lib/types/dag.nix index a42ed513..901f8868 100644 --- a/lib/types/dag.nix +++ b/lib/types/dag.nix @@ -1,33 +1,31 @@ # From home-manager: https://github.com/nix-community/home-manager/blob/master/modules/lib/types-dag.nix # Used for ordering configuration text. -{lib}: let - inherit - (lib) - defaultFunctor - nvim - mkIf - mkOrder - mkOption - mkOptionType - types - ; +{ + lib, + nvf-lib, + ... +}: let + inherit (lib.types) attrsOf defaultFunctor listOf mkOptionType str submodule; + inherit (lib.modules) mkIf mkOrder; + inherit (lib.options) mkOption; + inherit (nvf-lib.dag) isEntry entryAnywhere; dagEntryOf = elemType: let - submoduleType = types.submodule ({name, ...}: { + submoduleType = submodule ({name, ...}: { options = { data = mkOption {type = elemType;}; - after = mkOption {type = with types; listOf str;}; - before = mkOption {type = with types; listOf str;}; + after = mkOption {type = listOf str;}; + before = mkOption {type = listOf str;}; }; config = mkIf (elemType.name == "submodule") { data._module.args.dagName = name; }; }); maybeConvert = def: - if nvim.dag.isEntry def.value + if isEntry def.value then def.value else - nvim.dag.entryAnywhere ( + entryAnywhere ( if def ? priority then mkOrder def.priority def.value else def.value @@ -53,7 +51,7 @@ in rec { # "actual" attribute name a new submodule argument is provided with # the name `dagName`. dagOf = elemType: let - attrEquivalent = types.attrsOf (dagEntryOf elemType); + attrEquivalent = attrsOf (dagEntryOf elemType); in mkOptionType rec { name = "dagOf"; diff --git a/lib/types/default.nix b/lib/types/default.nix index c91473a2..3ef0ff9a 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -1,14 +1,6 @@ -{ - lib, - self, -}: let - typesDag = import ./dag.nix {inherit lib;}; - 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; +args: { + inherit (import ./dag.nix args) dagOf; + inherit (import ./plugins.nix args) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; + inherit (import ./languages.nix args) diagnostics mkGrammarOption; + inherit (import ./custom.nix args) char hexColor mergelessListOf singleOrListOf; } diff --git a/lib/types/languages.nix b/lib/types/languages.nix index b1865c41..d0476d61 100644 --- a/lib/types/languages.nix +++ b/lib/types/languages.nix @@ -1,4 +1,4 @@ -{lib}: let +{lib, ...}: let inherit (lib.options) mkOption mkPackageOption; inherit (lib.attrsets) attrNames; inherit (lib.types) listOf either enum submodule package; diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 4be39289..d51eba1e 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -1,11 +1,14 @@ { lib, + nvf-lib, self, + ... }: let inherit (lib.options) mkOption; inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair; 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. fromInputs = { @@ -64,9 +67,9 @@ in { type = pluginsType; }; - luaInline = lib.mkOptionType { + luaInline = mkOptionType { name = "luaInline"; - check = x: lib.nvim.lua.isLuaInline x; + check = x: isLuaInline x; }; /* diff --git a/modules/default.nix b/modules/default.nix index a479bae2..8b157bb2 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,7 +1,7 @@ { self, inputs, - lib, + ... }: { pkgs, extraSpecialArgs ? {}, @@ -10,17 +10,20 @@ extraModules ? [], configuration ? {}, }: let + inherit (pkgs) lib; + inherit (lib.modules) evalModules; 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 # 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 # optionally with any additional modules passed by the user - module = lib.evalModules { + module = evalModules { specialArgs = extraSpecialArgs // { @@ -30,12 +33,12 @@ modules = concatLists [ nvimModules modules - (lib.optional (configuration != {}) (lib.warn '' + (optional (configuration != {}) (warn '' nvf: passing 'configuration' to lib.neovimConfiguration is deprecated. '' configuration)) - (lib.optionals (extraModules != []) (lib.warn '' + (optionals (extraModules != []) (warn '' nvf: passing 'extraModules' to lib.neovimConfiguration is deprecated, use 'modules' instead. '' extraModules))