A flake.nix which configures an instance of nixos.
The flake uses sops-nix for secrets management, where the secrets are stored in a separate, private, github repo.
I want to deploy this flake with nixos-anywhere (i.e. there is a disko config, etc).
This has so far worked for me very nicely and turned out to be a quite sustainable way to have reoccurring deployments.
My issue is that I need to repeat this for a Raspberry Pi 4B. Getting the image onto the SD card is a bit more of a headache than I would like, but that worked fine. The issues started with the disko config. This is somewhat more complicated than I would like and even discouraged by the maintainer of disko (see this thread here).
Before continuing into this directioin, I thought it might make more sense to just create the correct image, with everything I want so that I can just flash that from the start onto the Pi. Building the image worked fine after some tinkering, but my issue here is that I dont know how to sanely deploy the ssh key needed to decrypt the sops secrets.
So to summarize options and maybe ask questions:
nixos-anywhere + disko: Is this feasible, i.e. has anybody tried it and had success with it?
Build SD Image: Not sure how to get the secrets to decrypt the sops-file to the SD card correctly. Any ideas on how to approach this?
Does the community have any input on which method is preferable?
This means one must boot a nixos installer image, probably from USB which requires a little bit of setup on a Raspberry Pi as I recall, and then using Nixos-Anywhere through that.
Which is all a little awkward, which is why I elected to not bother reinstalling, and keep my existing install based on the prebuilt sdimage.
This is not to say that using Nixos-Anywhere and Disko is not possible, I am pretty sure it is possible, just that I looked into it and elected not to bother.
Regarding the build sdimage sops issue, I think I just used the prebuilt image, login as nixos, update sops config with the autogenerated sshkeys, and rebuild to my config. Pretty manual, but I last did this when my nix skills were up to nothing more interesting.
Yep, that seems exactly right, and is how I recall doing it some months ago. Except my flake is public, and so no ssh key adding to any git provider was required, just use https.
Again, there are almost certainly more elegant solutions requiring less manual work, but that is what I used when I last did this.
So, I recently came back to this issue to redeploy my PI, and found that one can actually use nixos-anywhere, one must just install from a bootable USB rather than trying to kexec into an image from SD card.
A quick run through is:
Firstly, create an SD image for the appropriate RaspberryPi using GitHub - nvmd/nixos-raspberrypi: Nix flake for a fully declarative NixOS on Raspberry Pi . Somewhat confusingly, this can actually be flashed to a USB stick and then booted. To do so, remove the SD card from the PI, insert the USB stick, and power on. Once booted to the USB stick one should see the root password and such on screen. Insert the SD card. Now one can treat the raspberry pi as one would any system for installation using nixos-anywhere.
I did not look into this too much, as I prefer using nixos-anywhere. And it was not immediately clear to me how to add secrets when using repart, so I went ahead with nixos-anywhere.
I built this week a setup to create an image with disko that you can then flash onto the SD card.
What isn’t part of it yet is generating the host keys to then decrypt the agenix secrets. However this shouldn’t be too hard to add as I already generate and copy the SSH keys for SSH in initrd to be able to unlock the LUKS remotely. Adding the main host SSH keys should be basically the same.
The whole thing boots with UEFI and uses the normal NixOS kernel as that works for my needs just fine but I don’t use any special Raspberry Pi features atm.
I am in a similar situation - I wish to achieve a fully-automated deployment of NixOS on my Raspberry Pi 4 (including disk partitioning/formatting) using NixOS-anywhere. Could you elaborate a bit more on this step?
I tried generating one of the installer images (after disabling image compression) with nix build /my/fork/of/nixos-raspberrypi#installerImages.rpi4. The image builds successfully, and I can flash it on a USB stick (I configured my Pi 4 to boot from usb beforehand). Attempting to boot the image would result in a black screen shortly after NixOS stage 1.