Skip to content

Conversation

@MattSturgeon
Copy link
Member

@MattSturgeon MattSturgeon commented Nov 21, 2025

This PR adds two new builder functions, buildNixvim and testNixvim, which provide a simpler interface for building and testing Nixvim configurations. This is the first step toward deprecating the older builders:

  • makeNixvim
  • makeNixvimWithModule
  • mkTestDerivationFromNvim
  • mkTestDerivationFromNixvimModule

Both functions accept any of the following:

  • raw args for evalNixvim
  • an evaluated Nixvim configuration
  • a package with a Nixvim config passthru

A new helper, wrapEvalNixvim, normalizes these inputs so callers do not need to distinguish between forms.

Built packages now expose config and options in passthru, which allows them to be reused as input to testNixvim. Tests ensure that the new builders mirror the argument structure of evalNixvim.

Doccomments are provided, but prominent user documentation is deferred until the new interfaces have time to settle.

Top-level lib or flake aliases are also not added; for now these functions are only available under the lib.nixvim.modules namespace.

The extend function (added by the legacy makeNixvimWithModule standalone wrapper) is also not implemented for packages built without the legacy builder. Currently I'm unsure if we should replace that interface, or if we should suggest users use alternative methods like extendModules and/or importing common modules into different configurations.

Introduce a thin wrapper around `<configuration>.config.build.package`,
intended to replace the legacy `makeNixvim` and `makeNixvimWithModule`
functions.
Introduce a thin wrapper around `<configuration>.config.build.test`,
intended to replace the legacy `mkTestDerivationFromNvim` and
`mkTestDerivationFromNixvimModule` functions.
Similar to the legacy "standalone wrapper" `makeNixvimWithModule`,
thread the configuration's `config` and `options` to the final package.

This allows using such a package as the input to functions like
`testNixvim`.
Copy link
Member

@GaetanLepage GaetanLepage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Looks more straightforward.

Copy link
Contributor

@khaneliman khaneliman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall just couple thoughts on living doc stuff

mkConfigAt = "It has been moved to `lib.plugins.utils`";
};

wrapEvalNixvim =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do with a docstring as well explaining the purpose and what it does for us smooth brains.

Seems like this is the part that can handle a raw configuration or an already evaluated one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got lazy because this is private/internal and was extracted from functions that already had doc-comments. But you're right; this has enough logic and complexity to warrant some explanation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're fine, just figured I'd try to suggest something to aid anyone working with it who might not be as familiar with the nixpkgs lib functions involved to make it easier to understand what's happening here.

/**
Build a Nixvim package.
This is a thin wrapper around `<nixvim-configuration>.config.build.package`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line kinda confused me in the context of the rest of the docstring. We are building a package but it says its a thin wrapper around the output of a built package? Or am I reading it wrong?

Copy link
Member Author

@MattSturgeon MattSturgeon Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely challenging to phrase clearly.

It is saying that it returns the build.package option from a nixvim configuration.

In module system terminology, a "configuration" is the canonical name for the result of evaluating modules using evalModules. I.e. it has _type = "configuration";.

Technically, buildNixvim also accepts anything that has a config attr, including packages with passthru.config. But I don't want to distract from the key point.

I'm guessing there's simply not enough context that we're talking about the module system?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. so ...around the ... option ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but "option" alone doesn't do it justice, since it extracts the option value from a configuration (or any duck that looks like a configuration).

Perhaps something like "this function returns the build.package option's value, as defined in the supplied nixvim configuration"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that sounds good to me.

lib/modules.nix Outdated
Comment on lines 72 to 78
3. A Nixvim package, as produced by `buildNixvim`.
# Output
An installable Nixvim package.
*/
buildNixvim = lib.mirrorFunctionArgs self.modules.evalNixvim (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the buildNixvim mentionned in the docstring the same as this buildNixvim?
Otherwise, wouldn't you feed buildNixvim with a Nixvim package, as produced by buildNixvim?

lib/modules.nix Outdated
testNixvim = lib.mirrorFunctionArgs self.modules.evalNixvim (
input:
let
configuration = if input ? config.build.package then input else self.modules.evalNixvim input;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe overkilled, but we could factorize this line in a separate function. Maybe that won't help with understanding though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants