What changed, and why it matters
This commit changes a build script for Trezor's Nordic (nRF) hardware so it can automatically detect whether it is running inside a Docker/Nix build environment or a local developer's machine, and then run the build command the appropriate way. It is a build-system convenience change with no visible security relevance.
No security action required; review as normal build-system maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies nordic/trezor/scripts/build_sign_flash.sh. It adds a detect_environment() helper that checks for GNUARMEMB_TOOLCHAIN_PATH and ZEPHYR_TOOLCHAIN_VARIANT (indicating a pre-configured toolchain, e.g. Docker/Nix) or the presence of nrfutil (local development). run_under_ncs_subshell() now branches: in a configured environment it evals the command directly; otherwise it sources the nrfutil toolchain-manager environment in a subshell as before. The change is purely about build-environment detection and execution path selection.
Changed components
nordic/trezor/scripts/build_sign_flash.shInspect captured patch +27 / −3
diff --git a/nordic/trezor/scripts/build_sign_flash.sh b/nordic/trezor/scripts/build_sign_flash.sh
index d9960870..017d1bc3 100755
--- a/nordic/trezor/scripts/build_sign_flash.sh
+++ b/nordic/trezor/scripts/build_sign_flash.sh
@@ -21,10 +21,34 @@ fatal() {
exit 1
}
+# Auto-detect environment and choose appropriate execution method
+detect_environment() {
+ # Check if we're in Docker environment for reproducible build
+ # e.g. Docker/Nix with pre-configured toolchain for reproducible build
+ if [ -n "$GNUARMEMB_TOOLCHAIN_PATH" ] && [ -n "$ZEPHYR_TOOLCHAIN_VARIANT" ]; then
+ return 0 # Use direct execution
+ elif command -v nrfutil > /dev/null 2>&1; then
+ # We have nrfutil available (local development)
+ return 1 # Use nrfutil subshell
+ else
+ # Fallback to direct execution
+ echo "Warning: Neither nrfutil nor pre-configured toolchain detected, using direct execution"
+ return 0
+ fi
+}
+
run_under_ncs_subshell() {
- # In the subshell, toolchain environment is sourced then the command is run
- (source <(nrfutil toolchain-manager env | perl -pe 's/^(\w+)\s*:\s*(.*)/export \1=\2/'); bash -x -c "$@") \
- || fatal "Error in subshell"
+ detect_environment
+ local use_direct=$?
+
+ if [ $use_direct -eq 0 ]; then
+ # Docker/Nix environment - run directly
+ eval "$@" || fatal "Error in direct command execution"
+ else
+ # Local development environment - use nrfutil
+ (source <(nrfutil toolchain-manager env | perl -pe 's/^(\w+)\s*:\s*(.*)/export \1=\2/'); bash -x -c "$@") \
+ || fatal "Error in nrfutil subshell"
+ fi
}
usage() {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.