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

Add support for plugins that provide a new subcommand #2600

Closed
wants to merge 8 commits into from

Conversation

kirelagin
Copy link
Member

This feature has been documented for quite some time but never really worked. Now it does.

The only visible change is that previously plugins were loaded after all of the command line was parsed (so, obviously, subcommands provided by plugins were ignored), now they are loaded after the subcommand name has been parsed and right before the subcommand is resolved. Therefore, the plugin-files option has no effect if it comes after the subcommand name. Ideally, a warning should be issues in this case, but I have no idea how to do this.

See also #2597.

@kirelagin
Copy link
Member Author

(cc @edolstra)

@edolstra
Copy link
Member

edolstra commented Jan 7, 2019

Looks good to me, could you resolve the merge conflict?

BTW we could also get rid of libmain (i.e. merge it into src/nix) since it's not really useful anymore now that we have a single binary.

@7c6f434c
Copy link
Member

7c6f434c commented Jan 8, 2019

Do we already truly have a single binary? Isn't nix-env still separate (and without full replacement)? Even nix-build has functionality not conveniently available in nix build

@kirelagin
Copy link
Member Author

@7c6f434c Yep, all those are symlinks to nix.

In order to make it actually possible to implement plugins that define
custom subcommands, `RegisterCommand`, `Command`, and derived classes
should be in a library, not in the `nix` executable.

Specifically, with this change:

* It is now possible to `#include <command.hh>` from a plugin.
* Executables, other than `nix` itself`, will no longer crash if a
plugin that uses `ReigsterCommand` is loaded.

Fixes NixOS#2597
This way plugins can be initialised and subcommands added to the list
even after an instance of `MultiCommand` is created.
Before this change plugins were initialised only after resolving the
subcommand, so providing a subcommand from a plugin was not possible.
@kirelagin
Copy link
Member Author

Rebased.

@kirelagin
Copy link
Member Author

@edolstra ping!

@kirelagin
Copy link
Member Author

👋

@kirelagin
Copy link
Member Author

:(

@edolstra
Copy link
Member

Could this be done without moving installables.{cc,hh} to libmain?

BTW the flakes branch introduces a couple of nested subcommands (nix flake <command>, nix profile <command>). Maybe we want to make those extensible as well.

@kirelagin
Copy link
Member Author

I think, it can be done, but why though? Many plugins will want to parse commands and, in particular, work with installables, so it makes sense to have this code in the library. command.{cc,hh} will definitely have to go there, and if you prefer to live installables.cc in src/nix/ then it might be possible to extract the relevant declarations from command.hh into installables.hh (which doesn’t exist). But why exactly don’t you want to move them?

@edolstra
Copy link
Member

installables.{cc,hh} and command.{cc,hh} contain a lot of stuff specific to the nix command (like the Installable class) which isn't relevant to other programs that use libmain (like Hydra). It might make sense to move MultiCommand and RegisterCommand to libutil.

@stale
Copy link

stale bot commented Feb 13, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 13, 2021
@stale
Copy link

stale bot commented Apr 16, 2022

I closed this issue due to inactivity. → More info

@stale stale bot closed this Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants