Printing labels via SSH with Raspberry Pi Zero and Nix
16 points by nmattia
16 points by nmattia
I remember in a NixCon (2022?) someone gave a talk about needing to run really old versions of Firefox because they need support for Flash or something similar, and how they got it running with Nix just by pinning an older version of nixpkgs. This is why reproducibility is important.
Thanks for this writeup!
I use a Raspberry Pi to drive my regular Brother printer with CUPS, but every so often the microSD gets corrupted, and I have to spend an hour remembering how I’ve configured it. I eventually kept a copy of the fully configured disk image, but that’s kind of hacky.
I’ve wanted to switch over to NixOS, but NixOS support for the Pi 4 is surprisingly spotty. I hadn’t considered doing Raspbian + Nix, as that might work.
The Raspberry Pi Zero is already (hard?) wired as microUSB “host” (for the curious: by shorting this extra “ID” pin to ground).
I believe this is incorrect.
The Pi Zero’s USB port supports USB OTG. I did a proof of concept showing how to use the Pi Zero’s USB OTG functionality to make the Pi pretend to be a USB keyboard and type keys.
I somehow managed to build a nixos disk image without nix installed on a raspberry pi 2B.
It does have the advantage that it’s more persistent this way.
But there’s basically no documentation and I don’t even understand what I did exactly looking at the nix files I have.
And it took ages, because I had to cross compile the whole package stack ._.
I’ve wanted to switch over to NixOS, but NixOS support for the Pi 4 is surprisingly spotty. I hadn’t considered doing Raspbian + Nix, as that might work.
You might want to give this another try today. I only started using NixOS on a Pi 4 (2GB memory) around mid 2024, so I don’t know if this worked in 2023, but here’s my approach:
rpi4rf = nixpkgs.lib.nixosSystem {
modules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64-installer.nix"
./default.nix
./hosts/rpi4rf/default.nix
{
sdImage.compressImage = false;
nixpkgs.hostPlatform = "aarch64-linux";
}
];
};
and then build a custom SD image by running:
nix build .#nixosConfigurations.rpi4rf.config.system.build.sdImage
The image is then ready to be dd
’ed to a SD card and has everything build-in, my user + ssh keys, wifi setup, packages, etc.
nixos-rebuild
on my laptop and specify --target-hots
pointing to the Pi, because the Pi doesn’t have enough RAM usually to run a Nix build.Ah, nice! So this is wired as “host” by default but this can be changed in the config?
Re NixOS: I tend to avoid it when I can and go as far as possible using regular Ubuntu/Debian with Nix! Of course this doesn’t scale when you need to run services.
Right, there’s a better explanation here:
https://www.rmedgar.com/blog/using-rpi-zero-as-keyboard-setup-and-device-definition/
Great read, thanks for sharing. Will also have to check out the other articles in the series.