NBPR.Buildroot.Backend.Container (NBPR v0.2.1)

Copy Markdown View Source

Shared runner for the container-based backends (NBPR.Buildroot.Backend.Docker, NBPR.Buildroot.Backend.Podman, and future CLI-compatible runtimes).

Runs a Buildroot build inside the canonical Nerves build container (ghcr.io/nerves-project/nerves_system_br:latest). The in-container bash script is identical across runtimes — only the outer invocation differs (which executable, and whether the extracted output must be chowned back to the host user), so the concrete backends are thin wrappers that call build!/2 with those two knobs.

Why

The containerised env avoids subtle host-vs-canonical differences in toolchain wrappers, sysroot paths, and ABI flags when mix nbpr.build is invoked outside mix nerves.system.shell.

Storage layout

BR's per-package mode rsyncs files between intra-build directories with --hard-links. macOS Docker bind mounts (osxfs / VirtioFS) don't support hardlinks, so the BR build dir cannot be a bind mount on those hosts.

Instead the build dir lives in a named volume keyed by (system, BR version):

  • nbpr_build_<system>_<br_version> — persistent across runs
  • mounted inside the container at the same path the host would use (so env vars like BR2_DL_DIR, NERVES_DEFCONFIG_DIR work without path translation)
  • hardlinks work because volumes are native Linux filesystems

After make succeeds, the per-package output is copied from the volume to a host bind-mounted dir so NBPR.Buildroot.Harvest and NBPR.Pack (both running on the host) can read it.

Cleanup

Volumes persist across runs. Periodically remove them (docker volume rm / podman volume rm), or add a mix nbpr.cache.clean task later.

Summary

Functions

Returns true when executable is on PATH.

Runs the BR build for spec inside a container using executable.

Functions

available?(executable)

@spec available?(String.t()) :: boolean()

Returns true when executable is on PATH.

build!(spec, opts)

@spec build!(
  NBPR.Buildroot.Backend.spec(),
  keyword()
) :: Path.t()

Runs the BR build for spec inside a container using executable.

Options:

  • :executable — the container runtime to invoke (e.g. "docker", "podman"). Must be CLI-compatible for the run/-v/-e/--user subset used here.
  • :chown_output? — whether to chown -R the extracted output back to the host user inside the container. Needed under docker / rootful podman (container runs as real root); harmful under rootless podman (which already writes host-owned files).

Returns the harvest dir (spec.output_dir <> ".extract"), containing per-package/<br_package>/, ready for NBPR.Buildroot.Harvest.harvest!/2.