NBPR.Buildroot (NBPR v0.2.1)

Copy Markdown View Source

Discovery helpers for building nbpr packages against the user's pinned Buildroot tree.

After mix deps.get, the user's project contains deps/nerves_system_br/ with everything we need to drive a per-package Buildroot build:

  • create-build.sh — pins NERVES_BR_VERSION=<version> (e.g. 2025.11.3)
  • scripts/download-buildroot.sh — fetches the BR tarball from upstream
  • patches/buildroot/ — Nerves-specific patches that must be applied before building anything against this BR tree (otherwise nbpr packages will build against an incompatible upstream BR and may fail at runtime)
  • external.desc, external.mk, Config.in, package/ — Nerves' BR external tree, exposing extra packages and the nerves toolchain hooks

This module reads what's needed from there. Actual build invocation lives in subsequent modules.

Summary

Functions

Reads the pinned NERVES_BR_VERSION from nerves_system_br's create-build.sh. The returned string is the upstream Buildroot release identifier, e.g. "2025.11.3".

Returns the absolute path to deps/nerves_system_br/ in the active Mix project's deps tree, or {:error, :not_found} if it isn't a dep.

Returns the absolute path to nerves_system_br/ under deps_path, or {:error, :not_found} if absent.

Lists the patch filenames (relative to patches_path/1) in the order Buildroot's patch script expects them — sorted lexicographically, which matches the leading numeric prefix convention (0001-..., 0002-...).

Returns the path to nerves_system_br's buildroot patch directory, or {:error, :not_found} if absent. These patches must be applied to the upstream BR tree before any build.

Functions

br_version(nerves_system_br_path)

@spec br_version(Path.t()) :: {:ok, String.t()} | {:error, term()}

Reads the pinned NERVES_BR_VERSION from nerves_system_br's create-build.sh. The returned string is the upstream Buildroot release identifier, e.g. "2025.11.3".

nerves_system_br_path()

@spec nerves_system_br_path() :: {:ok, Path.t()} | {:error, :not_found}

Returns the absolute path to deps/nerves_system_br/ in the active Mix project's deps tree, or {:error, :not_found} if it isn't a dep.

Use nerves_system_br_path/1 when the lookup needs to span a different Mix project (e.g. a generator running inside the :nbpr library that needs to locate the workspace's nerves_system_br).

nerves_system_br_path(deps_path)

@spec nerves_system_br_path(Path.t()) :: {:ok, Path.t()} | {:error, :not_found}

Returns the absolute path to nerves_system_br/ under deps_path, or {:error, :not_found} if absent.

patch_files(patches_dir)

@spec patch_files(Path.t()) :: [String.t()]

Lists the patch filenames (relative to patches_path/1) in the order Buildroot's patch script expects them — sorted lexicographically, which matches the leading numeric prefix convention (0001-..., 0002-...).

patches_path(nerves_system_br_path)

@spec patches_path(Path.t()) :: {:ok, Path.t()} | {:error, :not_found}

Returns the path to nerves_system_br's buildroot patch directory, or {:error, :not_found} if absent. These patches must be applied to the upstream BR tree before any build.