Raspberry Pi headless installation?

I’ve been trying to install NixOS on a Raspberry Pi headlessly (no keyboard, no mouse, no monitor, just power, storage and a network connection) for a couple of hours now because I lost my micro HDMI adapter and I realised pretty quickly that I need to build my own ISO to do this properly, so that’s what I’ve been trying to do.

Using this method results in a flashable image but I can’t for the life of me determine if the RPi boots or not, but, in any case, I can’t see it on the router, I can’t ping it, so it likely is not there at all.

Using this method some derivations are having trouble building so I don’t think it’s even my fault. Also I found this one just randomly, I didn’t research it much.

Any help? I’ve been struggling for a while + the hours waiting for stuff to build. I just don’t wanna buy another one of those cursed adapters.

The easiest would probably be to connect a USB keyboard and blindly enter sudo passwd nixos and then any password. After that you should be able to SSH into the pi from your actual machine using ssh nixos@yourmachinehere. This works with the regular NixOS image.

As for building a custom image, you have two options: Cross-compile or compile using emulation.

Many packages are broken in cross compilation but a rather minimal closure should work. Build a minimal image that is only able to accept an SSH connection from your hosts and then do a rebuild into your actual config. Disable anything you don’t need outside of that.

Another option is to build the image natively using emulation. Here you execute aarch64 code on your x86_64 machine using emulation. Though since most derivations will be in the binary cache, you’ll likely only build a few extremely small derivations that barely need any processing power. Simply set boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; on your build machine and make the configuration to be built a native aarch64-linux one.

If only I knew that would’ve worked. I had no idea in what state the basic image starts. Autologin because it has no password, I had no idea.

So what I was doing is cross compilation ain’t it? I compiled tons of stuff to generate an image.

And that’s all? The exact same things I wrote in my flake will work and do their job, and switch from cross-compilation to emulation?

Note that it’s auto login and no password; these two are independent.

Correct.

As I said, you must make your NixOS built as aarch64-linux natively rather than cross.

The method with building the image should work just fine.
When the network port blinks it should be booting.
I haven’t seen where you defined your network config, if you used a static IP it won’t show up on your router.

I’ve had some success using a combination of GitHub - MatthewCroughan/raspberrypi-nixos-example: The simplest possible way to begin using and extending a NixOS Configuration with a Raspberry Pi for the initial image and GitHub - MatthewCroughan/nixinate: Another NixOS Deployment Tool - Nixinate your systems 🕶️ for updating remotely.

I don’t think I had to do anything special to be able to SSH into it.