Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/overlay: init #2328

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion flake-modules/overlays.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ inputs, ... }:
{
self,
inputs,
...
}:
{
imports = [ inputs.flake-parts.flakeModules.easyOverlay ];
perSystem =
Expand All @@ -15,4 +19,10 @@
};
};
};
flake.overlays = {
# Export our lib extension overlay
# Note: this is an overlay for nixpkg's lib, not for nixpkgs itself
# You can pass the overlay to `lib.extend`
lib = import ../lib/overlay.nix { };
};
}
7 changes: 5 additions & 2 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ lib.fix (
# Used when importing parts of helpers
call = lib.callPackageWith {
inherit call pkgs self;
lib = extendedLib;
helpers = self; # TODO: stop using `helpers` in the subsections
lib = self.extendedLib;
};

# Handle "extended" lib
# FIXME: We probably don't need this internally within out lib...
extendedLib = if lib ? nixvim then lib else lib.extend (import ./overlay.nix { inherit self; });

# Define this outside of the attrs to avoid infinite recursion,
# since the final value will have been merged from two places
builders = call ./builders.nix { };
Expand All @@ -35,7 +39,6 @@ lib.fix (
{
autocmd = call ./autocmd-helpers.nix { };
deprecation = call ./deprecation.nix { };
extendedLib = call ./extend-lib.nix { inherit lib; };
keymaps = call ./keymap-helpers.nix { };
lua = call ./to-lua.nix { };
modules = call ./modules.nix { };
Expand Down
18 changes: 0 additions & 18 deletions lib/extend-lib.nix

This file was deleted.

23 changes: 23 additions & 0 deletions lib/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# TODO: remove `args` and standardise how we build lib.nixvim
# Ideally, `lib` should be the _only_ argument expected by lib.nixvim
{
self ? null,
}:
# Extends nixpkg's lib with our functions, as expected by our modules
final: prev: {
# Include our custom lib
# To avoid redundant work, we allow a nixvim-lib instance to be supplied
# TODO: is this needed, or would nix's laziness do the same thing automagically?
nixvim = if self != null then self else import ./. {
# TODO: final vs prev here...
lib = prev;
};

# Merge in our maintainers
maintainers = prev.maintainers // import ./maintainers.nix;

# Merge in our custom types
types = prev.types // import ./types.nix {
lib = final;
};
}
2 changes: 1 addition & 1 deletion wrappers/_shared.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ in
lib.nixvim = lib.mkDefault (import ../lib { inherit pkgs lib; });

# Make nixvim's "extended" lib available to the host's module args
_module.args.nixvimLib = lib.mkDefault config.lib.nixvim.extendedLib;
_module.args.nixvimLib = lib.mkDefault (lib.extend (import ../lib/overlay.nix { }));
}

# Use global packages by default in nixvim's submodule
Expand Down