Skip to content

lib/plugins: enforce one url per plugin#3674

Merged
GaetanLepage merged 2 commits intonix-community:mainfrom
MattSturgeon:assert-one-url
Sep 10, 2025
Merged

lib/plugins: enforce one url per plugin#3674
GaetanLepage merged 2 commits intonix-community:mainfrom
MattSturgeon:assert-one-url

Conversation

@MattSturgeon
Copy link
Member

@MattSturgeon MattSturgeon commented Sep 9, 2025

As per #3653 (comment)

We already assert that a URL is defined. Now we also asserts that multiple URLs are not defined.

As an example, this is what the errors typically look like:

$ nix eval .#docs
«error: The option `plugins.bullets.url' has conflicting definition values:
- In `/nix/store/2ys1mzni2v8m7j6bxlvn6ib7rx9aj0r8-source/plugins/by-name/bullets': "https://github.com/bullets-vim/bullets.vim"
- In `/nix/store/4bdm5fcwix168v4l6rr9p7a9iafgp6zs-source/pkgs/applications/editors/vim/plugins/generated.nix:1881': "https://github.com/bullets-vim/bullets.vim/"
Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.
»

@MattSturgeon

This comment was marked as resolved.

This asserts that we don't accidentally end up with conflicting
definitions.

Such conflicts must be made explicit, e.g. using `mkForce` or `mkDefault`.
@MattSturgeon MattSturgeon marked this pull request as ready for review September 9, 2025 23:55
@MattSturgeon MattSturgeon requested a review from a team September 9, 2025 23:57
Copy link
Contributor

@DataHearth DataHearth left a comment

Choose a reason for hiding this comment

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

LGTM! Good feature to compact package definition👌

@GaetanLepage GaetanLepage added this pull request to the merge queue Sep 10, 2025
Merged via the queue into nix-community:main with commit c55042f Sep 10, 2025
5 checks passed
@daniellaing
Copy link
Member

I like this, great work!
Maybe it's worth adding a small descriptive error message to help explain why there are conflicting definitions? Something like "Plugin URL is already definied in nixpkgs, no need to define it here." or similar.

@MattSturgeon
Copy link
Member Author

MattSturgeon commented Sep 10, 2025

Maybe it's worth adding a small descriptive error message to help explain why there are conflicting definitions? Something like "Plugin URL is already definied in nixpkgs, no need to define it here." or similar.

Good suggestion. I initially had a more bespoke solution with errors along those lines, but I decided to leverage the module system's merge function instead.

This strikes a balance between not needing to re-implement much logic vs having full control.

Most of the error message comes from the module system, which is why it talks about options and definitions. The parts we can influence without re-writing the merge function are the "locations"; i.e. the "option path" and the "definition locations".

I figured since this is likely to only be seen in new plugin PRs and in lockfile update PRs, the current error is fine.

I did put some effort into getting sane locations for the definitions; e.g. the meta.homepage location is the actual in-store location where homepage is defined in nixpkgs.

EDIT: maybe we could add some "error context" though? This would show up above the error in the stack trace as a "...while evaluationplugins.foo's URL" context line.

@MattSturgeon MattSturgeon deleted the assert-one-url branch September 10, 2025 12:24
@MattSturgeon
Copy link
Member Author

EDIT: maybe we could add some "error context" though? This would show up above the error in the stack trace as a "...while evaluationplugins.foo's URL" context line.

I've just tested this, and using builtins.addErrorContext doesn't help here.

The error gets thrown by the module system from another context, so wrapping addErrorContext around the meta or url attributes doesn't show up in the stack trace, even with --show-trace.

I think the current solution is fine, but as always, if someone has ideas for how to improve it I'd welcome a PR. 😁

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.

4 participants