Skip to content

RegisterCommand plugins still resolve too late for top-level nix <plugin-cmd> (2.36) #16498

Description

@mikenrafter

Summary

plugin-files / RegisterCommand is documented as the way to add nix subcommands (man nix.conf, manual). On current CppNix (reproduced on 2.36pre20260912_203f85b2), a plugin that registers a top-level command is visible in nix --help and NIX_GET_COMPLETIONS, but nix <cmd> … fails with '<cmd>' is not a recognised command.

This is the same class of bug as #2597 / the intent of #4486, still present on master.

Reproduction

  1. Build a trivial RegisterCommand("scout") plugin (or any name) against the running nix / nix-cmd ABI.
  2. Load it without any PATH wrapper:
NIX_CONFIG="plugin-files = /path/to/nix-scout.so" nix --help | grep scout
# → · nix scout - …

NIX_GET_COMPLETIONS=1 NIX_CONFIG="plugin-files = …" nix '' | grep scout
# → scout is offered

NIX_CONFIG="plugin-files = …" nix scout --help
# → error: 'scout' is not a recognised command

Cause

In RootArgs::parseCmdline (src/libutil/args.cc), the first non-flag argument is handled via MultiCommand::processArgs, which looks up the subcommand in the pre-plugin command map and throws if missing.

initialFlagsProcessed() → initPlugins() → pluginsInited() (which refreshes commands = RegisterCommand::getCommandsFor({}) in src/nix/main.cc) runs only after the entire cmdline has been parsed.

That contradicts the comment on Args::initialFlagsProcessed() in args.hh (“Called after all command line flags before the first non-flag argument”) and the design from #4486 (load plugins after initial flags, then resolve the subcommand).

Expected

With plugin-files set in nix.conf (or as an initial flag before the subcommand), nix <plugin-cmd> … should dispatch to the plugin-registered command, matching the documented RegisterCommand API.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions