Skip to content

Conversation

k1gen
Copy link
Contributor

@k1gen k1gen commented Jul 17, 2025

Fix nix help shell by properly handling command aliases

Closes: #13431

Problem

The nix help shell command incorrectly fails with Nix has no subcommand 'shell' despite nix shell --help working correctly. This happens because shell is actually an alias for env shell, and the help system wasn't resolving these aliases when looking up documentation.

This creates a confusing user experience where the shell command both exists and doesn't exist depending on how users try to access its documentation.

Solution

This PR modifies the showHelp function in src/nix/main.cc to check for and resolve aliases before generating the manpage name. When a user requests help for an aliased command like shell, the system now correctly looks up the documentation for the actual command (env shell).

The implementation is straightforward - it adds a few lines to the showHelp function to check if the requested subcommand matches any aliases in the toplevel.aliases map, and if so, replaces the subcommand with the actual command path before generating the manpage name.

Previously, `nix help shell` failed with "Nix has no subcommand 'shell'" despite `nix shell --help`
working correctly. This happened because the `shell` command is actually an alias for `env shell`,
and the help system wasn't resolving aliases when looking up documentation.

This patch modifies the `showHelp` function to check for and resolve aliases before generating the
manpage name, ensuring that shorthand commands like `shell` get proper help documentation.

Closes: NixOS#13431
@k1gen k1gen requested a review from edolstra as a code owner July 17, 2025 15:29
@github-actions github-actions bot added the new-cli Relating to the "nix" command label Jul 17, 2025
@Mic92 Mic92 merged commit 599c1d7 into NixOS:master Jul 17, 2025
12 checks passed
@Mic92 Mic92 added backport 2.30-maintenance Automatically creates a PR against the branch backport 2.26-maintenance Automatically creates a PR against the branch backport 2.28-maintenance Automatically creates a PR against the branch and removed backport 2.26-maintenance Automatically creates a PR against the branch labels Jul 17, 2025
mergify bot added a commit that referenced this pull request Jul 17, 2025
…3496

Fix `nix help shell` by properly handling command aliases (backport #13496)
Mic92 added a commit that referenced this pull request Jul 17, 2025
…3496

Fix `nix help shell` by properly handling command aliases (backport #13496)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.28-maintenance Automatically creates a PR against the branch backport 2.30-maintenance Automatically creates a PR against the branch new-cli Relating to the "nix" command
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nix help command doesn't recognize shell as a subcommand
2 participants