Building OpenWRT with Nix (discuss on 35C3?)

I’m looking for people experienced in building OpenWRT and Nix, as I’m interested in how to build the first with the latter.

I think it wouldn’t be too difficult to build everything as one derivation, but that wouldn’t provide good caching and would result in huge output sizes. So I’m looking really how to replace the OpenWRT build system with Nix.

I’m currently on 35C3, so I’d be happy to meet up and discuss the topic in person.

1 Like

You might have found that one already: nix-environments/envs/openwrt at master · nix-community/nix-environments · GitHub
This provides the environment for building openwrt. The first thing you would need to do is packaging their SDK, which is basically the build toolchain that includes all their compiler, linker and other build-tools. I see several options there in increasing order of difficulty

  1. Download & Patchelf their SDK (take a look at our android infrastructure: Mobile updates by svanderburg · Pull Request #50596 · NixOS/nixpkgs · GitHub)
  2. Use our pkgsCross to emulate their SDK with our build tools (don’t forgot that we use cc-wrappers, so use the unwrapped compilers).
  3. Try to build the SDK (I had problems with NixOS doing that, they had a few shebangs, but something forced me to use buildFHSUserEnv but I no longer remember the exact issues)

From their one could make use of their data structures to import their checksums into nix with by sourcing their checksums with make and to download them with fetchurl:

If you can extract the packages that a particular openwrt config tries to build then you could make sure to download all sources ahead of time and maybe split each package into its own derivation followed by a final image building step.
The openwrt buildsystem is stupid but quiet effective at hiding useful error message from the user, to debug it is useful to remove some 2>/dev/null redirections from their Makefiles or use something like sysdig -c stderr. I am also on 35c3 and also abradar is. I am not so much interested in pulling that exact project of as this is quiet a lot of work I would rather like to put into improving our cross-compiling infrastructure, but I would be at the assembly, if you want to discuss some details.

1 Like

Thanks Jörg, yeah I found your env already a few years ago. I’ll visit
the assembly for your cross compiling workshop.

I am still very interested in building OpenWRT. In the meanwhile, I have abstracted the imagebuilder just because its sha256sums were easily available on GitHub - astro/nix-openwrt-imagebuilder: Build OpenWRT images in Nix derivations

I run ~50 OpenWRT devices where ~30% have 4 MB flash. I’ve gone some lengths to use imagebuilders of OpenWRT 18.06.9 for these. My hope for building custom firmware is to customize a current OpenWRT release by excluding lots of stuff. I wonder why they don’t release just the imagebuilder for the targets with only 4 MB flash?

1 Like