diary at Telent Netowrks

Post title goes here#

Thu, 31 May 2018 23:54:36 +0000

It's taken more than a little while to get NixWRT back into the brain again, partly due to needing a change and partly due to work/family stuff. Currently in progress: breaking the backuphost.nix monolith into composable modules, such that I (or a user, when in the fulness of time the project acquires any users) can add the various parts separately.

This was prompted by a question on the NixOS Discourse site - and the current status, which is experimental, is that a module is a function which gets some options and a pointer to nixpkgs, then operates on the big configuration attrset and returns an augmented version of it. That's handwaving, so let me show you bits of it: in modules/default.nix we have for example

  syslogd = options: nixpkgs: configuration:
    with nixpkgs;
    lib.attrsets.recursiveUpdate configuration {
      services.syslogd = {
        start = "/bin/syslogd -R ${options.loghost}";
        depends = ["eth0.2"];
      };
    };

and then in backuphost.nix we have

let modules = (import ./nixwrt/modules/default.nix);
    # ...
    wantedModules = with modules; [
      (rsyncd { password = rsyncPassword; })
      sshd
      (syslogd { loghost = "192.168.0.2"; })
      (ntpd { host = "pool.ntp.org"; })
      (dhcpClient { interface = "eth0.2"; inherit busybox; })
    ];
    configuration = lib.foldl (c: m: m nixpkgs c) baseConfiguration wantedModules;

This differs from the NixOS module system because we pass per-module config to the module itself instead of having it root around in one big configuration attrset. (In theory this means we could have two modules with the same name but differently customised, which might be useful). But it's also dependent on the order that the module functions are applied in, which makes me feel it would be nice to do some kind of fixpoint thing the way that overlays do. Or at least to find some nice way to have modules add their configuration to busybox and for them to be able to refer to busybox and for it to be the same busybox derivation used by all modules. The same consideration may very well apply to the kernel.

Anyway, it may be that I need to spend a bit more time on this before I understand why NixOS modules do it differently and I should switch to their approach, or it may be that my requirements are not those of NixOS.

In other news I have bought a proper USB TTL serial cable, so next time I crack open a new piece of router hardware I can plug it straight into a USB port on my desktop system instead of needing a Raspberry Pi as an sshable serial console. The next target is a TrendNET 712BR and I may have to think a bit about how to develop on it because unlike the MT300A or even the Yun it doesn't have an awful lot of spare RAM. Will have to think of something after I've found out how lobotomised its u-boot is or isn't.

Solder but no wiser#

Wed, 13 Jun 2018 07:17:21 +0000

Everyone should have at least one hobby that they're no good at and/or dislike doing.

For me that was once playing guitar (still have the instrument, no longer have the calluses) but these days it's soldering. So after having stuck three short pieces of paperclip into adjacent holes inside my Trendnet TEW712BR and showered them with blobs of molten tin, I was as surprised as anybody when I plugged my USB TTL serial converter in and found I had a root console.

Notes for others who may follow this way:

It turns out I'm slightly ahead of myself in doing this right now, because although I have an image for Milestone 1 that runs on an Arduino Yun, it's too big - there is only 4MB flash in this little box. Still, at least I am able to capture a boot log and find out its partition scheme and kernel load address.

Yes, I have working wifi, and the use case for "WiFi access point/range extender" (WiFi in AP mode via hostapd, bridged to Ethernet, and a DHCP client). This entailed

Mostly fairly straightforward stuff so far - or at least, at a remove of anything up to two weeks since I did some of this work, I've forgotten whatever problems I ran into. It's all in wap.nix , which still copies a bit too much code from backuphost.nix but that will change as soon as I can get my head around fixpoints. To get it to fit into flash on the device I'm going to need a smaller kernel and perhaps a smaller busybox.

I will try to fix you#

Thu, 21 Jun 2018 19:30:36 +0000

Last week I had hooked up the serial port on my upstairs wifi access point. This week I'm posting this blog entry through it. Which is a win, I think.

All is not finished yet, though, because the NixWRT install on it is too big for the teeny tiny 4MB flash chip and is running in RAM. Which means I can't put the case back on yet. So I've been working on ways to make the image smaller, which mostly has been about removing kernel options I don't need and busybox applets it doesn't use.

To do this, I have changed the module system to introduce - without, I admit, fully understanding - the fix-point pattern as used in package overlays. The deal here is that many packages may wish to change the compile-time options for busybox/the kernel, and simultaneously they also wish to use the resulting binary - and as packagers we want them all to use the same binary instead of making a new kernel/busybox for every package that needs a slightly different one. This is a mutually recursive dependency, but mercifully it's a mutually recursive dependency with a base case. What this means is that a module now takes self and super parameters where the super is a configuration attrset that it can modify and return, and the self is the "final" shape of that attrset that it can use for references to other packages and things that it needs but is not modifying. That's not an exact explanation of how to use this pattern, but it's basically the limit of my understanding of it.

Rearranging things in this way has led to a couple of nice features: for example, I can now add a module to introduce the kernel phram support that is only needed for TFTP boots (and thus have it excluded from the flashable image) or the 9p filesystem support that's only relevant to qemu builds. It also means my image size is now down to 1635k (kernel) plus 2600k (root), but squeezing out the final 300k or so that I'll need (I don't have an exact number but u-boot and ART partition will want space) is proving to be somewhat challenging. When this device was produced it was using a 3.x series kernel and I think 4.9 just unavoidably has a bit more heft in it.

Incidentally, backuphost.nix is assumed broken by this latest set of changes. Some day soon I will figure out a workable CI process for this project.

In other news, finally finished moving stuff off my old Debian shell host to a Nixos installation. Obligatory Bytemark plug goes here.

Shrunk but it came unlunk#

Fri, 29 Jun 2018 14:17:56 +0000

I finally "persuaded" NixWRT to produce an image less than 4MB large and am successfully posting this through it. But then I decided to update the Nixpkgs it's built on from a fork that diverged last February to current master, and guess what? It all broke again!

Presently I'm at the "thinking hard about the problem" stage of debugging, but this may soon progress to the git bisect stage of debugging, because I haven't had any good ideas yet.