nix-community / disko

Declarative disk partitioning and formatting using nix [maintainers=@Lassulus @Enzime @iFreilicht]
MIT License
1.81k stars 194 forks source link

Using disko to generate raspberry pi sd card images #550

Open crazyminecuber opened 8 months ago

crazyminecuber commented 8 months ago

Is it possible to generate SD card images and deploy to a Raspberry Pi using disko to configure the sd image partitions? When I tried, it got errors because the SD card image generator (nixos/modules/installer/sd-card/sd-image-aarch64-new-kernel-no-zfs-installer.nix) tries to use ext4 as root file system, and therefore it does not want to compile. I think this would be really nice to use the same disko configuration format for generating SD images as you use for installing x86 systems.

The main problem I want to solve is to be able to use the btrfs file system to use impermanence, while also being able to generate the sd-card image from scratch.

Mic92 commented 2 months ago

I think with our disko's make-disk-image it should be possible. The main part that needs to be replicated is installing firmware/bootloader, as you can see here: https://github.com/NixOS/nixpkgs/blob/eb9dbcd4e116ecb69dde3040102f6a7bfa8b1aab/nixos/modules/installer/sd-card/sd-image-raspberrypi.nix#L18 or here: https://github.com/NixOS/nixpkgs/blob/eb9dbcd4e116ecb69dde3040102f6a7bfa8b1aab/nixos/modules/installer/sd-card/sd-image-aarch64.nix#L22

If you don't have an arm builder at your disposal it should be also be possible to use boot.binfmt.emulatedSystems on a x86_64 machine to run the image generation. I believe the default boot process for rpis is still to have a fat32 partition? The alternative would be something like towboot, which might give you more flexibility.