I'd like to build an image for a Raspberry Pi with impermanence / a read-only sd card - Is there a guide for sth like that?

I want to build an Raspberry Pi image, build on my workstation so I can just dd it to an SD card.

There seem to be several guides on how to do that. But: I need the entire SD card read-only because the RasPi can loose power at any time.

In the past I’ve done that with a script like this. And now I’d like to do this with NixOS. I read about impermanence but I can’t manage to combine the concepts. Is there anyone who did something like that and wrote some blog article that I didn’t find? Is Impermanence the correct concept to do something like this?

And a bonus question: What’s the current situation with binary caching and the armv7 architecture? Is there still nothing out there? I’d try and tinker around until I find a solution on my own, but building images takes so much resources…

1 Like

I run a raspberry pi 3 with impermenance as an IPMI gateway, see my config https://git.sr.ht/~magic_rb/dotfiles/tree/master/item/nixos/systems/gooseberry i hope it help. Feel free to prod me with questions :slight_smile:

2 Likes

Awesome. Thank you very much.

Regarding the cache I’ve had better experience using aarch64 instead of armv7.

While my project is currently in the fridge, I’ve collected some raspberry pi related links that might be relevant to you. Unfortunately nothing in there directly answers your question.

1 Like

The URL is not valid anymore. Any chance you could post a new one to the configuration?

I took down my dotfiles for security reasons and mild paranoia. Ill post a up to date version just for you. (Though be warned i dont consider my dotfiles anywhere near “best practices”)

That’s essentially what I do for my own Rasperry Pis running NixOS. I’m using a small FAT32 boot partition containing the required firmware, and a larger btrfs root partition containing subvolumes for/nix and /persist. (Strictly speaking, my setup isn’t read-only because I still wanna do automatic upgrades, but it wouldn’t be an issue to mount /nix and /boot with ro.

It’s relatively straightforward to either write a flashing script or a derivation that builds the filesystems with userspace tooling exclusively. I’d recommend using the upstream SD card image derivation over at nixpkgs/nixos/modules/installer/sd-card/sd-image.nix at f4d595514856b921dd31c90cc02eb8d917a37a3f · NixOS/nixpkgs · GitHub as a template and modify the partitioning-specific parts.