NixOS on RPi4 SSD

I’m trying to get NixOS running on a SSD attached to a Raspberry Pi 4 B via USB. I have the RPi4 booting from USB. It can boot RaspBerry Pi OS images from the SSD. However, everything I’ve tried via NixOS can’t mount the root partition from initrd. Over the last two weeks I’ve read a dozen different blog posts and wiki entries about this, and followed those directions plus the variations I could think of. I’m stuck.

Can someone point me in the right direction? Or is running from USB not possible right now?

Thanks for any and all help!

/rob

I’m booting a Pi 4 from an SSD – haven’t had any crazy issues. The repo I have that configuration in is private, but a few excerpts if they’d be helpful:
I build the image as:

        gaia = nixos-generators.nixosGenerate {
          modules = [
            ./hosts/gaia
          ];
          pkgs = legacyPackages."aarch64-linux";
          format = "sd-aarch64-installer";
        };

where nixos-generators is GitHub - nix-community/nixos-generators: Collection of image builders [maintainer=@Lassulus]

and the default.nix referenced is basically just:

{ lib, pkgs, config, modulesPath, ... }:
with lib;
{

  # base image
  imports = [
    "${modulesPath}/installer/sd-card/sd-image-aarch64.nix"
  ];
  sdImage.compressImage = false;

}

I write the image to the SSD using dd as

sudo dd if=result/sd-image/nixos-sd-image-23.05.20230105.a518c77-aarch64-linux.img of=/dev/sda bs=64k status=progress

and then it boots. I add some other stuff to enable ssh and tailscale so I can connect headlessly, but that’s pretty much it.

Happy to help if you have any other issues.

It never occurred to me to build a customized image. I’ll read about how to do that. Thanks!

Okay, some progress. Importing all-hardware is enough to get it to boot. I didn’t know about this module before; it lists every module that might help into boot.initrd.availableKernelModules. Now I’ll try to figure out which modules I actually need.

imports = [
    ...
    <nixpkgs/nixos/modules/profiles/all-hardware.nix>
  ]
1 Like