Building OpenWRT with Nix (discuss on 35C3?)


#1

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.


#2

You might have found that one already: https://github.com/nix-community/nix-environments/tree/master/envs/openwrt
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: https://github.com/NixOS/nixpkgs/pull/50596)
  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.


#3

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