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

Command plugins #4486

Merged
merged 3 commits into from Feb 24, 2021
Merged

Command plugins #4486

merged 3 commits into from Feb 24, 2021

Conversation

shlevy
Copy link
Member

@shlevy shlevy commented Jan 28, 2021

This makes it possible to define and use external plugins that add new nix subcommands.

Tested both with the existing in-tree plugins test and with an external command-adding plugin.

@shlevy
Copy link
Member Author

shlevy commented Jan 28, 2021

Alternative implementation of #4479

@shlevy
Copy link
Member Author

shlevy commented Feb 2, 2021

@edolstra Thoughts on this one?

@shlevy
Copy link
Member Author

shlevy commented Feb 13, 2021

@edolstra Ping.

@shlevy
Copy link
Member Author

shlevy commented Feb 17, 2021

@edolstra if there are no objections I'll merge this soon.

@edolstra
Copy link
Member

Please not, I'm not so happy about making it impossible to pass --option after the subcommand. That's suboptimal UX.

@shlevy
Copy link
Member Author

shlevy commented Feb 17, 2021

@edolstra It's not impossible, it's just a warning. The only option that can't be passed after the subcommand is plugin-files. We can remove the deprecation warning too.

@shlevy
Copy link
Member Author

shlevy commented Feb 19, 2021

@edolstra Can we set up some time next week to talk through next steps? Maybe Monday in the EST morning?

@flokli
Copy link
Contributor

flokli commented Feb 22, 2021

Is there any further read about this feature in general, about what plugins are supposed to do/access, and what not?

I'm somewhat worried exposing the somewhat in flux internal Nix API, which was never stable or formalized to plugins either will lead to not being able to change internal API (cause people are afraid to break plugins), or changes in Nix suddenly causing breakages (cause there is no contract about what's stable).

@shlevy
Copy link
Member Author

shlevy commented Feb 22, 2021

@flokli plugins predate this work, and in fact we thought command plugins already worked: https://nixos.org/manual/nix/stable/#conf-plugin-files

There is no expectation of stability around these APIs, or there shouldn't be.

This PR simply fixes when command plugins are loaded so they can take effect.

@flokli
Copy link
Contributor

flokli commented Feb 22, 2021

There is no expectation of stability around these APIs, or there shouldn't be.

@shlevy thanks for the clarification. The section in the manual isn't clear enough for my taste regarding stability guarantees, but that's probably out of scope for this PR.

@shlevy
Copy link
Member Author

shlevy commented Feb 22, 2021

@flokli You're right, fixed 35205e2

@flokli
Copy link
Contributor

flokli commented Feb 23, 2021

Thanks!

doc/manual/src/release-notes/rl-2.4.md Outdated Show resolved Hide resolved
doc/manual/src/release-notes/rl-2.4.md Outdated Show resolved Hide resolved
src/libutil/args.cc Outdated Show resolved Hide resolved
doc/manual/local.mk Outdated Show resolved Hide resolved
doc/manual/local.mk Outdated Show resolved Hide resolved
We know the flag will be ignored but the user wants it to take effect.
This is technically a breaking change, since attempting to set plugin
files after the first non-flag argument will now throw an error. This
is acceptable given the relative lack of stability in a plugin
interface and the need to tie the knot somewhere once plugins can
actually define new subcommands.
@shlevy
Copy link
Member Author

shlevy commented Feb 24, 2021

@edolstra Updated with removal of the deprecation.

@edolstra edolstra merged commit 199081a into NixOS:master Feb 24, 2021
@edolstra
Copy link
Member

Thanks!

@edolstra edolstra mentioned this pull request Feb 24, 2021
@aakropotkin
Copy link
Contributor

aakropotkin commented Feb 1, 2023

What is the correct way to load plugins to avoid the error message?
I have tried everything I can think of, and while nix doesn't actually crash, I'm going to have to wrap the executable in something to swallow this error message because I cannot get it to go away.

warning: error: plugin-files set after plugins were loaded, you may need to move the flag before the subcommand

These all emit the warning/error ( unsure of which it actually is since it's stated as being both a warning and an error ):

nix --plugin-files "$PWD/libfoo.so" CMD ...;
nix --option plugin-files "$PWD/libfoo.so" CMD ...;
nix CMD --plugin-files "$PWD/libfoo.so" ...;
nix CMD --option plugin-files "$PWD/libfoo.so" ...;
NIX_CONFIG="plugin-files = $PWD/libfoo.so" nix CMD ...;

This one convinced me the error message was just completely bogus:

(
  export XDG_CONFIG_HOME="$( mktemp -d; )";
  cp -r -T -- "$HOME/.config/nix" "$XDG_CONFIG_HOME/nix";
  echo "plugin-files = $PWD/libfoo.so" >> "$XDG_CONFIG_HOME/nix/nix.conf";
  nix CMD ...;
);

I can file a bug report but wanted to check to make sure I wasn't just using the flags incorrectly or something.

@shlevy
Copy link
Member Author

shlevy commented Feb 2, 2023

@aakropotkin fixed in #7736

@shlevy
Copy link
Member Author

shlevy commented Feb 2, 2023

@aakropotkin Note that even without this fix nothing actually fails to work, you just get this erroneous warning message. The client does in fact load the plugin-files.

@aakropotkin
Copy link
Contributor

aakropotkin commented Feb 2, 2023

Yeah luckily the plugins still work which is the most important thing.

Out of curiosity @shlevy have you encountered crashes on exit using allocValue from plugins? I know you use them quite a bit and thought you might know how to deal with them. Notably these only seem to appear on Darwin. I'm guessing it's a static initialization issue, but haven't had time to do a deep debug session.

I've tried this block a dozen ways and always hit a syscall failure on exit : https://github.com/aakropotkin/floco/blob/54f5bf1bbff1f5d3dd81577ad258b46121aef05f/pkgs/nix-plugin/npm-wrap.cc#L138
Works fine on Linux. I've tested a minimal case and I've found that calling allocValue at all will cause the issue.
Placing the same code in primops.cc also works.

@shlevy
Copy link
Member Author

shlevy commented Feb 3, 2023

@aakropotkin I haven't, but my usage has been very sporadic, sorry.

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.

None yet

4 participants