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

xplr: fix cfg.plugins implementation for more than one plugin #4521

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

ChanceHarrison
Copy link
Contributor

Description

Would close #4520. Please see that issue (and the upstream discussion linked within) for more information.

Change the implementation of the programs.xplr.plugins option to correctly set the package.path in the written Lua config file.

Specifically, each component path of the package.path must have appropriate wildcard/template characters (what Lua calls "interrogation marks" or ? characters).

Furthermore, due to the need (in the current implementation) to use programs.xplr.extraConfig to call require(<plugin-name>).setup, this implementation ensures that plugins in the Nix store are inside a predictably-named directory.

Checklist

  • Change is backwards compatible.

Unfortunately not. The cfg.plugins option currently takes a list for while it is proposed that it takes an attribute set.

While a change could be made that maintains complete backwards compatibility, one could argue that the usability improvements that accompany the change (of an already broken option) outweigh the cost of breaking back-compat.

  • Code formatted with ./format nixfmt.

  • Code tested through nix-shell --pure tests -A run.all or nix develop --ignore-environment .#all using Flakes.

  • Test cases updated/added. See example.

  • Commit messages are formatted appropriately

Maintainer CC

@NotAShelf

Copy link
Contributor

@sayanarijit sayanarijit left a comment

Choose a reason for hiding this comment

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

Minor suggestions. Other than that, pr looks good. cc @NotAShelf for further review.

modules/programs/xplr.nix Outdated Show resolved Hide resolved
modules/programs/xplr.nix Outdated Show resolved Hide resolved
@NotAShelf
Copy link
Contributor

Minor suggestions. Other than that, pr looks good. cc @NotAShelf for further review.

I'm in favor of approving this PR as is (with our without the changes you've mentioned) but I really would like some second opinion on the plugin wrapper. I'll try communicating on matrix about this.

modules/programs/xplr.nix Outdated Show resolved Hide resolved
else
builtins.dirOf value;

makePluginSearchPath = p: "${p}/?/init.lua;${p}/?.lua";
Copy link

Choose a reason for hiding this comment

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

This whole wrapping thing seems strange, what happens if you wrap a plugin in a store path that doesn't have init.lua? I assume it won't match because it'd have to be ${p}/?/?.lua not just ${p}/?.lua

Alternatively, we might consider only allowing plugins with init.lua (and we can get rid of all this wrapping and wildcard fluff).

Copy link
Contributor

Choose a reason for hiding this comment

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

init.lua is a must for every plugin as documented in https://xplr.dev/en/writing-plugins. There's no plugins without init.lua at root dir.

Copy link

Choose a reason for hiding this comment

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

Actually wouldn't ${p}/?.lua be sufficient (without this wrapper)? Maybe I missed some discussion, but why does the init.lua case need to be handled separately?

Copy link
Contributor

Choose a reason for hiding this comment

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

With only ${p}/?.lua, we'd need to import the plugin as require('name.init') rather than require('name'), assuming the entrypoint is name/init.lua. It's a lua convention to add init.lua in package path to make the lib easy to import.

Also, without the wrapper, there's no way to import the plugin by name (since init.lua will be inside hash, not hash/name), unless the plugin structure changes, breaking the entire ecosystem.
Trying to import plugins by hash instead will not work, since plugins also do importing.

Copy link

Choose a reason for hiding this comment

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

Then I think my original comment applies?

what happens if you wrap a plugin in a store path that doesn't have init.lua? I assume it won't match because it'd have to be ${p}/?/?.lua not just ${p}/?.lua

Copy link
Contributor

Choose a reason for hiding this comment

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

The wrapping does this:
/nix/store/hash/init.lua ->
/nix/store/hash/name/init.lua

So we can add package.path = "/nix/store/hash/?/init.lua;/nix/store/hash/?.lua" and require("name").

To understand the issue better, let's reproduce it.

  1. Create /fakenixstore.
  2. Git clone sayanarijit/trash-cli.xplr as /fakenixstore/hashsha123 such that sayanarijit/trash-cli.xplr/init.lua is now /fakenixstore/hashsha123/init.lua.
  3. Get into lua repl (in any dir) and modify package.path in a way so that you can run require("trash-cli").setup().

Here you'll see that the only probably the best way to make it work is to:

  1. move or symlink /fakenixstore/hashsha123/* as /fakenixstore/hashsha123/trash-cli/*.
  2. In lua repl, run package.path = "/fakenixstore/hashsha123/?/init.lua;/fakenixstorestore/hashsha123/?.lua"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eclairevoyant Based on the most recent message, is it clear why the wrapping method is being used? Do you see any better way? If I or someone can provide more clarification, just say the word. Otherwise, feel free to resolve the conversation.

@ChanceHarrison
Copy link
Contributor Author

@NotAShelf I'm in favor of approving this PR as is (with our without the changes you've mentioned) but I really would like some second opinion on the plugin wrapper. I'll try communicating on matrix about this.

Thanks for the review. Did anything come out of your communications on Matrix regarding the plugin wrapping?


To all: Aside from the unresolved conversation regarding the plugin wrapping, I am moving this PR out of draft status based on the feedback received. If there is anything else you would like addressed, just let me know.

@ChanceHarrison ChanceHarrison marked this pull request as ready for review October 8, 2023 08:18
@NotAShelf
Copy link
Contributor

I haven't received any responses on matrix but rycee has already given a review - I also asked a few other people to provide their own.

I'll go ahead and approve this.

@sayanarijit
Copy link
Contributor

Hi @rycee I think this is good to go, if no-one has any concern.

Fixes ##4520

Co-authored-by: Arijit Basu <11632726+sayanarijit@users.noreply.github.com>
@rycee rycee merged commit c36cb65 into nix-community:master Jan 4, 2024
3 checks passed
@rycee
Copy link
Member

rycee commented Jan 4, 2024

Thanks! Merged to master now. If there is any residual concerns about the wrapper, perhaps those could be resolved in a future PR.

@ChanceHarrison ChanceHarrison deleted the xplr-plugins branch February 21, 2024 08:41
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.

bug: xplr: cfg.plugins does not work for more than one plugin
6 participants