lib: allow instantiating without a flake instance

Separate `overlay.nix` and `overlay.internal.nix`, to encapsulate the
`flake` argument. This allows non-flake users to import `./overlay.nix`
without providing a dummy `flake = null` attr.

The read-only `config.flake` option is only defined by `evalNixvim` when
`lib` is extended using the overlay in Nixvim's flake outputs.
This commit is contained in:
Matt Sturgeon 2026-05-19 14:42:10 +01:00
parent f58f056882
commit fca03f1759
6 changed files with 52 additions and 42 deletions

View file

@ -84,7 +84,8 @@ When Nixvim is built in standalone mode, it expects `lib` to have Nixvim's exten
If you'd like to use a `lib` with your own extensions, you must supply it via `specialArgs`,
however you must ensure Nixvim's extensions are also present.
This can be achieved using the lib overlay, available via the `<nixvim>.lib.overlay` flake output.
This can be achieved using the lib overlay, available via the `<nixvim>.lib.overlay` flake output
or importing the `lib/overlay.nix` file.
```nix
# Example flake

View file

@ -14,7 +14,7 @@
# on pinning the flake-parts nixpkgs-lib to the nixpkgs pin
inherit (inputs.nixpkgs) lib;
};
overlay = import ../lib/overlay.nix {
overlay = import ../lib/overlay.internal.nix {
flake = self;
};
# Top-top-level aliases

View file

@ -1,7 +1,7 @@
{
lib,
self,
flake,
flake ? null,
}:
let
removed = {
@ -34,10 +34,10 @@ in
lib.evalModules {
modules = modules ++ [
../modules/top-level
{
(lib.optionalAttrs (lib.isAttrs flake) {
_file = "<nixvim-flake>";
flake = lib.mkOptionDefault flake;
}
})
(lib.optionalAttrs (system != null) {
_file = "evalNixvim";
nixpkgs.hostPlatform = lib.mkOptionDefault { inherit system; };

42
lib/overlay.internal.nix Normal file
View file

@ -0,0 +1,42 @@
/**
Internal function returning Nixvim's Nixpkgs `lib` overlay.
Publicly accessible at `./overlay.nix` and the `nixvim.lib.overlay` flake output.
*/
{ flake }:
/**
Overlay function extending the Nixpkgs `lib` with Nixvim's additions.
This function is intended to be passed to `lib.extend`.
# Examples
Importing the file directly:
```
lib.extend (import (nixvim + "/lib/overlay.nix"))
```
Using the overlay from flake outputs:
```
lib.extend nixvim.lib.overlay
```
# Inputs
`lib`
: The final lib instance; the fixpoint of all extensions, including this one.
`prevLib`
: The lib instance prior to applying this overlay.
*/
lib: prevLib: {
# Add Nixvim's section to the lib
nixvim = import ./top-level.nix { inherit flake lib; };
# Extend the maintainers set with Nixvim-specific maintainers
maintainers = prevLib.maintainers // import ./maintainers.nix;
# Extend lib.types with Nixvim's custom types
types = prevLib.types // import ./types.nix { inherit lib; };
}

View file

@ -1,37 +1,4 @@
{ flake }:
/**
Overlay function extending the Nixpkgs `lib` with Nixvim's additions.
This function is intended to be passed to `lib.extend`.
# Examples
Importing the file directly:
```
lib.extend (import ./overlay.nix { flake = nixvim; })
```
Using the overlay from flake outputs:
```
lib.extend nixvim.lib.overlay
```
# Inputs
`lib`
: The final lib instance; the fixpoint of all extensions, including this one.
`prevLib`
: The lib instance prior to applying this overlay.
*/
lib: prevLib: {
# Add Nixvim's section to the lib
nixvim = import ./top-level.nix { inherit flake lib; };
# Extend the maintainers set with Nixvim-specific maintainers
maintainers = prevLib.maintainers // import ./maintainers.nix;
# Extend lib.types with Nixvim's custom types
types = prevLib.types // import ./types.nix { inherit lib; };
# Public non-flake entrypoint for Nixvim's Nixpkgs-lib overlay
import ./overlay.internal.nix {
flake = null;
}

View file

@ -16,7 +16,7 @@
*/
{
lib,
flake,
flake ? null,
}:
lib.makeExtensible (
self: