TL;DR: Personal toy project idea, asking for some guidance in how the existing Nerves platform works.
I have been toying with the idea of using Nix/NixOS to create a Nerves system, instead of using Buildroot. (As opposed to compiling Buildroot on NixOS, which is possible and I’m doing that for a project I’m working on. Required a couple of changes along the lines of file
isn’t in /usr/bin/
, nor is install, etc.) This should also give me some opportunity to get to understand how Nerves works more
I’m just putting this here in case people have ideas on it, though I can’t guarantee I’ll be spending a lot of time on it so it might not happen too fast.
Usual terminology when discussing Nix/NixOS/Nixpkgs:
- Nix :: a package manager, can be installed on Linux and MacOS (also WSL2). Takes a more formalized approach to package management which may make things like cross-compilation easier. Has the same problem as other things that take a formal approach though – may make some simpler things sounds more difficult.
- NixOS :: a Linux distro written as a Nix package. A Linux distro is after all (more or less), the kernel, bootloader, system services (systemd in this case) and a set of installed packages. (Usually people talk about it in terms of the OS they are using, but I have used it as an OS I’m cross-compiling, that needn’t be done from NixOS, any OS will do as long as it has Nix installed. You can absolutely use Nix without NixOS to build NixOS (e.g. build VM images, or a particularly fun case is called NixOS lustrate – where NixOS takes over the existing OS :p).
- Nixpkgs :: A huge set of packages (just look at https://repology.org/). Not all of them will cross-compile (looking at you, spidermonkey! – though maybe that’s now fixed, and polkit now supports duktape I think).
I have some prior experience with maintaining Nix packages, and with using Nix to cross-compile a NixOS for a Raspberry Pi.
Pros & Cons of Nix
- + Individual, isolated compilation of separate packages, including good tracking of when things don’t get changed. Currently my experience of buildroot is that the whole system gets rebuilt, especially in a CI context where you want a clean build each time. With Nix each package is built in isolation (as a clean build) so this shouldn’t be such a problem.
- + Declarative description of the system. Not sure if it’ll make sense to reuse NixOS or make something lighter (NixOS depends on systemd/is a bunch of systemd packages, plus uses Perl for “system activation”, kind of a step akin to install/upgrade in other Linux distributions). To be honest, I haven’t used Buildroot in this sense, only used someone else’s Buildroot config, so I don’t know how good/bad Buildroot is from this point.
- + It’s own management of artifacts/caching. I mean Nerves has a good go at this, though it doesn’t build things hermetically, i.e. things not in
nerves_package
underchecksum
can still end up in the resulting image. Also I’m not sure the URL of the artifact (or at least the root of the path) should be stored in the artifact itself, this makes mirrors a pain. - Not really a plus, more of a comment, but it can also do the toolchain not just the cross-compilation using the toolchain.
- - Nixpkgs not primarily being targeted at cross-compilation means package updates are more likely to break cross-compilation. Perhaps this needs a branch/tags of nixpkgs that build a usable system.
Here is my understanding of how things work:
- I would essentially be replacing
nerves_system_br
- The pertinent code for that is nerves/lib/nerves/system/br.ex at 82a1911eec7229eb10bce2d7cae5d06e4d8760a6 · nerves-project/nerves · GitHub and nerves_system_br/create-build.sh at main · nerves-project/nerves_system_br · GitHub
- I have had a look at Systems — nerves v1.10.5
- What I need to look at more is how the resulting
nerves_system_br
is used
Here is what I plan on doing:
- Getting a simple system to cross-compile for a Raspberry Pi
- Minimising that system to be a similar size to the existing Nerves Raspberry Pi system (~25MiB)
- Getting Nerves to use that system