# `NBPR.Buildroot.Builder`
[🔗](https://github.com/jimsynz/nbpr/blob/v0.2.0/lib/nbpr/buildroot/builder.ex#L1)

Source-builds an NBPR package artefact tarball end-to-end.

Driven from both `Mix.Tasks.Nbpr.Build` (CLI) and `Mix.Tasks.Nbpr.Fetch`'s
fallback path (when no prebuilt artefact is published for the active
(system, system_version, build_opts) tuple).

Pipeline:

  1. Discover `deps/nerves_system_br/` and read the pinned BR version.
  2. Ensure the patched BR source tree at
     `$NERVES_DATA_DIR/nbpr/buildroot/<version>/`.
  3. Render a defconfig that layers the package + its `build_opts` on top
     of the active system's `nerves_defconfig`.
  4. Run BR (`<pkg>-dirclean && <pkg>`) against a stable per-(system,
     BR-version) output dir, in Docker on non-Linux hosts.
  5. Filter per-package output via BR's files-list (runtime-only).
  6. Pack into the canonical artefact tarball at `output_dir/`.

Returns the absolute path to the produced tarball.

# `build!`

```elixir
@spec build!(NBPR.Package.t(), NBPR.Artifact.build_inputs(), Path.t()) :: Path.t()
```

Builds the artefact for `pkg` against `inputs.system_app`/`system_version`,
with `inputs.build_opts` applied. Writes the tarball into `output_dir` and
returns its absolute path.

`inputs` is the standard `t:NBPR.Artifact.build_inputs/0` map (the same one
used for cache-key/manifest computation in the fetch path).

# `stable_output_dir`

```elixir
@spec stable_output_dir(atom(), String.t()) :: Path.t()
```

Returns the stable per-(system, BR-version) BR output dir. Reusing across
builds keeps the toolchain extraction, host-skeleton, and unchanged packages
cached; `make olddefconfig` reconciles defconfig drift.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
