Precompiled
Install signed, verified precompiled builds of your Hex dependencies
instead of compiling them. Builds come from the
Nerves compatibility portal,
which builds Hex packages for the host, on each supported Elixir/OTP
toolchain, and for Nerves systems, signs a batch index every 15 minutes, and
serves files by SHA-256. Besides a build with and one without a package's
optional dependencies, it also builds packages with the optional
dependencies a typical Phoenix or Nerves app has, so a fresh mix phx.new
or mix nerves.new app gets most of its dependencies prebuilt. A
dependency is installed only when a build matches the project on every
rule in
What matches, including
being compiled with exactly the dependencies Mix compiles it with in your
project and env; everything else compiles as before, and nothing this
library does can fail your build.
Installation
With Igniter (Elixir 1.18 or later):
mix igniter.install precompiled
Or by hand, in mix.exs:
def project do
[
...,
aliases: [
"deps.loadpaths": ["deps.compile precompiled", "precompiled.deps", "deps.loadpaths"]
]
]
end
defp deps do
[
{:precompiled, "~> 0.10.0", runtime: false},
...
]
end
No config is needed: builds come from the portal's signed API by default. The source, its mirrors and the root of trust can be changed only in the project's config, never by an option or an environment variable (see Trust).
Usage
Nothing more: every mix compile, mix test, mix phx.server and
mix release installs the matching builds before Mix compiles the rest,
and prints one line per candidate:
precompiled: ash 3.36.0 HIT 4.1 MB; build 3f2a9c01b7de: Elixir 1.20.0/OTP 28
precompiled: nerves_pack 0.7.1 MISS built with nerves_ssh 1.3.3, project has 1.3.2; closest build 9b04e17ac2d5: Elixir 1.20.3/OTP 29, rpi4 2.2.2
precompiled: 40 hit, 5 miss, 0 fail of 45 deps, 61.2 MB, 8.3 s
In a script or a Livebook cell, with the archive installed:
Precompiled.Host.install([{:jason, "1.4.5"}, {:decimal, "3.2.0"}])
It takes the same options as Mix.install/2 (config:, config_path:,
lockfile: and so on) and checks builds against the dependency tree and
config that Mix.install/2 will compile with.
On a running Nerves device, from an IEx shell:
Precompiled.install(:circuits_gpio)
Precompiled.report()
precompiled: system nerves_system_rpi4 2.2.1, OTP 29, Elixir 1.20.3, aarch64
precompiled: circuits_gpio 2.3.1 PLAN nerves_system_rpi4, 198 KB
precompiled: circuits_gpio 2.3.1 OK /data/precompiled/circuits_gpio-2.3.1
precompiled: 1 installed, 198 KB, 2.1 s
precompiled: downloaded 1.1 MB (documents 912 KB, files 199 KB), reused 0 KB from the cache (documents 0 KB, files 0 KB)
The device checks everything itself, with no Mix and no project: the
signed batch, the exact system and release it runs, and what a build's
compile read, such as Mix.target() and CROSSCOMPILE, against its own
firmware. It keeps each manifest (the signed list of a package's builds
and their files) and the systems table by SHA-256, so a later install
downloads only what changed, and a build already in the store installs
with no network while the cached batch is still valid. The last line says
what was downloaded and what came from the cache (see
The cache).
In Nerves Livebook, Mix.install/2 can be Precompiled.mix_install/2,
which takes the same deps and options, skips what the firmware has and
raises a readable Precompiled.InstallError. One call at boot,
Precompiled.MixShim.define(), defines that Mix (see
Mix.install in Nerves Livebook).
Precompiled.report() shows the last install's HIT/MISS/FAIL lines and,
only after you answer yes, sends them to the portal, so a miss on your
device can be fixed (see
On a device).
PRECOMPILED=0 turns it off.
On a Linux glibc machine (x86_64 or aarch64),
config :precompiled, host_native: true also installs host-native builds
of NIF packages: beams and .so files built for this machine's triple,
ABI-compatible with it rather than identical to your own compile, so off
by default (see
Configuration).
On your build machine nothing is installed while something outside the
project would make your own compile differ from the published build: a
global rebar3 config that changes compile options, ERL_COMPILER_OPTIONS
(other than exactly deterministic, which takes builds compiled with it),
ERL_LIBS, compiler-affecting ERL_*FLAGS/ELIXIR_ERL_OPTIONS, or a
.erlang file. The line names the variable or file (never its value); see
Troubleshooting.
mix precompiled.report sends the last build's HIT/MISS/FAIL report,
after showing it and asking (see
Troubleshooting).
Guides
Getting started:
- Setup: any Mix project,
umbrellas, Phoenix, CI,
Mix.installand Livebook - Nerves
- On a device, including bundles for devices with no network
Reference:
- Configuration: every key and variable, turning it off, seeing what happened
- What matches: every rule, and which builds made on another release of your Nerves system still match
Explanation:
- Trust: the signed chain, on the host and on the device, and CA certificates
Troubleshooting:
- Troubleshooting: every line the library prints, and what to do
- Known limitations
The guides are also in guides/. To work on the library, see CONTRIBUTING.md.
Supported versions
Elixir 1.17 or later on OTP 27 or later; the Igniter installer needs Elixir 1.18. Builds serve only the toolchains the portal builds with (today Elixir 1.19.3 and 1.20.3 on OTP 28 and 29); see Supported versions.
Nerves systems with builds today: nerves_system_bbb,
nerves_system_mangopi_mq_pro, nerves_system_qemu_aarch64,
nerves_system_rpi, nerves_system_rpi0, nerves_system_rpi0_2,
nerves_system_rpi2, nerves_system_rpi3, nerves_system_rpi3a,
nerves_system_rpi4, nerves_system_rpi5, nerves_system_trellis and
nerves_system_x86_64. A dependency with no build for your system says so
and names the systems that have one.
Names
The package is precompiled; the repository keeps its old name,
elixir_precompiled. This library was called nerves_precompiled until
v0.1.0; those old config keys and environment variables still work for
one release (see Configuration).
The interim elixir_precompiled names (app, modules,
ELIXIR_PRECOMPILED_* variables, the cache dir) were never released and
are not read.
License
Apache-2.0. See LICENSE.