# `NBPR.Runtime`
[🔗](https://github.com/jimsynz/nbpr/blob/v0.7.0/lib/nbpr/runtime.ex#L1)

Runtime helpers for Application-bearing NBPR packages.

The generated `NBPR.<Name>.Application` module calls into here to decide
whether to load kernel modules and how. Keeping these as plain functions
in a stable module means: the codegen stays trivial, behaviour can be
changed centrally without rebuilding every package, and tests can target
the helpers directly.

# `load_kernel_module!`

```elixir
@spec load_kernel_module!(atom(), String.t()) :: :ok
```

Loads kernel module `name` for the package `otp_app`, and raises on failure.

Prefers the package's own priv-shipped `.ko`: stock Nerves systems index
only the modules the system was built with in `/lib/modules/<ver>/modules.dep`
(the rootfs is read-only, so `depmod` can't re-index on device), which makes
an out-of-tree module invisible to `modprobe`-by-name. Instead the `.ko` is
located under the package's priv dir and loaded by path with `insmod` from
`:nbpr_kmod`, after `modprobe`-ing its in-tree dependencies (read from the
module's `depends:` field via `modinfo`).

Falls back to plain `modprobe <name>` when the package doesn't ship the
`.ko` itself — i.e. the module is already indexed on the rootfs.

Idempotent: modules already loaded (per `/sys/module/`) are skipped.

# `modprobe!`

```elixir
@spec modprobe!(String.t()) :: :ok
```

Runs `modprobe <name>` and raises on failure.

modprobe is idempotent (re-loading an already-loaded module is fine) and
resolves its own dependency graph from `modules.dep`, so transitive kernel
modules don't need to be loaded explicitly. Only works for modules the
system's `modules.dep` indexes — for a package-shipped out-of-tree `.ko`,
see `load_kernel_module!/2`.

# `on_nerves_target?`

```elixir
@spec on_nerves_target?() :: boolean()
```

Returns `true` when the current process is running on a Nerves target.

Every Nerves system ships `ID=nerves` in `/etc/os-release`. Used to gate
kernel-module loading so `mix test` and dev workflows on macOS/Linux are
unaffected by package Applications.

---

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