Skip to content
Open
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
48 changes: 48 additions & 0 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ let
applyExtraConfig = "It has been moved to `lib.plugins.utils`";
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.

pred: fn:
lib.mirrorFunctionArgs self.modules.evalNixvim (
input: fn (if pred input then input else self.modules.evalNixvim input)
);
in
{
# Evaluate nixvim modules, checking warnings and assertions
Expand Down Expand Up @@ -57,6 +63,48 @@ in
}
// extraSpecialArgs;
};

/**
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.


# Inputs

`input`
: One of:
1. Arguments for `evalNixvim`.
2. A Nixvim configuration, as produced by `evalNixvim`.
3. A Nixvim package, as produced by `buildNixvim`.

# Output

An installable Nixvim package.
*/
buildNixvim = wrapEvalNixvim (input: input ? config.build.package) (
configuration: configuration.config.build.package
);

/**
Build a Nixvim test derivation.

This is a thin wrapper around `<nixvim-configuration>.config.build.test`.

# Inputs

`input`
: One of:
1. Arguments for `evalNixvim`.
2. A Nixvim configuration, as produced by `evalNixvim`.
3. A Nixvim package, as produced by `buildNixvim`.

# Output

A buildable Nixvim test.
*/
testNixvim = wrapEvalNixvim (input: input ? config.build.test) (
configuration: configuration.config.build.test
);
}
// lib.mapAttrs (
name: msg:
Expand Down
4 changes: 4 additions & 0 deletions modules/top-level/output.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
pkgs,
config,
options,
lib,
...
}:
Expand Down Expand Up @@ -319,6 +320,9 @@ in
printInitPackage
];
meta.mainProgram = "nvim";
passthru = {
inherit config options;
};
};

printInitPackage = pkgs.writeShellApplication {
Expand Down
10 changes: 10 additions & 0 deletions tests/lib-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,16 @@ let
"Nixvim (single-element): Trailing whitespaces"
];
};

buildNixvim_hasExpectedArgs = {
expr = lib.functionArgs lib.nixvim.modules.buildNixvim;
expected = lib.functionArgs lib.nixvim.modules.evalNixvim;
};

testNixvim_hasExpectedArgs = {
expr = lib.functionArgs lib.nixvim.modules.testNixvim;
expected = lib.functionArgs lib.nixvim.modules.evalNixvim;
};
};
in
if results == [ ] then
Expand Down