Repository navigation
cli: Run the nsh CLI the project pins - #2736
Open
YougLin-dev wants to merge 2 commits into
Open
YougLin-dev wants to merge 2 commits into
YougLin-dev wants to merge 2 commits into
Conversation
A project can pin the nsh CLI its toolchain expects in nsh.json, via toolchain.nsh.version (a release, e.g. 0.6.1) or toolchain.nsh.rev (a full Git commit). On every invocation, the running nsh reads the pin before any subcommand runs. If the selection matches this build it proceeds in place; otherwise the pinned CLI is looked up from the cache ($NSH_CACHE/toolchains/<owner>__<repo>/<tag-or-rev>/). On a cache miss, a release pin downloads the prebuilt archive from the repository's GitHub releases, verifies its SHA-256 and unpacks it; a Git-rev pin builds the CLI from the Cargo checkout at that revision. Either way, the running nsh replaces itself (exec) with the pinned CLI, forwarding the original arguments. No new command: the user runs `nsh`. Every nsh call site -- IDE tasks, agents, --target dispatch, bare `nsh add` -- goes through the same pin-aware entry.
Member
|
💡 Needs the maintainer's call: this adds a new public Reviewed head 40c69dc.
Suggest keeping this under the #2712 discussion until the maintainer decides whether NSH should pin its own CLI at all. |
A cloned project could otherwise escalate any `nsh` invocation into running code from an arbitrary fork. The SHA-256 we verify against the release proves integrity, not origin. `toolchain.nsh.repository` now defaults to longbridge/nsh and stays on that trust root. Any other repository is refused unless the user acknowledges it: set `NSH_TOOLCHAIN_ALLOW=owner/repo,...` for non-interactive runs, or accept an interactive prompt on a TTY. The gate fires before the install step, so a malicious project never downloads code on the way to failing.
Contributor
Author
|
Addressed the trust finding — that was a real bug, not a style choice. Pushed as
The rest of the findings are noted:
Holding for the #2712 design decision. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #2712
This is the in-
nshversion of the toolchain pin. No second binary, no second command. Users always runnsh.Description
A project can pin the nsh CLI it builds with, so every
nshcall into that project (including from outside an app directory) uses the pinned version:or pin an exact Git revision:
On every invocation, before any subcommand runs, the running
nsh:nsh.jsonand parsestoolchain.nsh.NSH_GIT_SHA_FULLfor a rev pin), proceeds in place — no extra process.$NSH_CACHE/toolchains/<owner>__<repo>/<tag-or-rev>/:nsh-<host>.{tar.gz,zip}from the repository's GitHub releases, verifies.sha256, unpacks.cargo build --release -p nsh-cli); the build target lives under the cache so cache cleans trigger a re-build.execs the pinned CLI with the original arguments, replacing this process.A project without a pin, or with a pin that matches the current build, runs in place. The pin check happens before any subcommand handler, so it catches
nsh run,nsh add,nsh test,--targetdispatch, etc. — there is no other entry point. No new command or binary name: the tool isnsh, period.Public API
nsh.json:"toolchain": { "nsh": { "version": "<release>", "rev": "<40-hex>", "repository": "<owner>/<repo>" } }— selects the CLI. Eitherversionorrevis required.repositorydefaults tolongbridge/nsh.NSH_CACHE— cache root (defaults to the platform cache directory plusnsh).How to Test
cargo test -p nsh-cli toolchain— 6 tests pass (pin parsing, validation, matching, tag prefix, cache root).cargo clippy -p nsh-cli --all-targets -- -D warnings— clean.cargo check -p nsh-cli— pass.toolchain.nsh.version = "0.6.1",nsh --versionfirst printednsh 0.6.1 (2f51d86)after downloading and unpacking the published archive; a second run finished in 0.02s; without a pin in the directory, the runningnshused its own version (no exec).No full
cargo test --workspacerun; only the CLI's resolver and the newtoolchainmodule changed. No UI or platform behavior touched.Checklist
cargo test --workspace,cargo +nightly fmt --alland clippy (including the Catalyst and Android runs for platform code). — Ran the affected crate's tests and clippy; see How to Test.tests/compat/(cargo xtask compat). — Newnsh.jsonkey; no app-facing API changed. Not applicable.examples/gallerydemos on iOS and Android (if the change is visible or platform-specific). — Not visible; not applicable.