Can I get something like nixos-anywhere on the Pi?

I’ve discovered the most satisfying way of getting stations up and running with NixOS.

  1. Boot an ISO I’ve built with SSH keys already installed
  2. nixos-anywhere, to install an initial NixOS
  3. nixos-rebuild, with my flake.

All done from the comfort of my velvet armchair. Only thing missing in this setup is something like the PiKVM, where I can emulate USB drives. Then I don’t even need to get up to insert or pull out the Live USB stick and the storage USB stick;)

Anyways, nixos-anywhere depends on x86, it seems, so, it’s not really anywhere;)

Does a workflow like this exist for Pi?

1 Like

There’s GitHub - MatthewCroughan/raspberrypi-nixos-example: The simplest possible way to begin using and extending a NixOS Configuration with a Raspberry Pi if you’re interested in making an SD Image. Then a deployment script might look like

deploy = pkgs.writeScriptBin "deploy.sh" ''
  nix copy ${self.nixosConfigurations.pi.config.system.build.toplevel} --to ssh://user@pi.local
  ssh -t user@pi.local 'sudo nix-env -p /nix/var/nix/profiles/system --set ${self.nixosConfigurations.pi.config.system.build.toplevel}'
  ssh -t user@pi.local 'sudo ${self.nixosConfigurations.pi.config.system.build.toplevel}/bin/switch-to-configuration switch'
'';
1 Like

I don’t think it’s relevant to Pi itself, you’re looking at deploying your configuration to running hosts?
Consider that a Pi may not have sufficient resources to run nixos-rebuild or would be quite slow and so shipping an already built image may be “more efficient”.

nixos-anywhere will still require some manual process either by manually booting an USB with NixOS installer or setting up network boot (Network Boot With Raspberry Pi: Everything you need to know – RaspberryTips):
https://github.com/nix-community/nixos-anywhere/blob/4c94cecf3dd551adf1359fb06aa926330f44e5a6/docs/howtos/no-os.md#installing-on-a-machine-with-no-operating-system

nixops may be more suitable for your use case as it lets you manage configurations on existing / running NixOS hosts:
https://releases.nixos.org/nixops/nixops-1.7/manual/manual.html#sec-deploying-to-physical-nixos

nixos-rebuild supports --build-host ; isn’t that for building locally, then deploying remotely?

Isn’t that exactly what nixos-rebuild remote does? Any advantage in using nixops?

I believe both nixos-anywhere and nixops could do the job
Solutions like nixops are more devops oriented / focus

Here’s a list of tools that could tackle your use case: Looking for alternative to NixOps - #3 by Janik

1 Like

Not sure what you mean here, cause nixos-anywhere doesn’t work on Pi.

Could you share your references on nixos-anywhere doesn’t work on Pi?

From requirements.md:

x86-64 or aarch64 Linux systems with kexec support. Note: While most x86-64 Linux systems support kexec, if you’re using an architecture other than those mentioned, you may need to specify a different kexec image manually

Main / only requirement would be having kexec on target device.
aarch64 is supported for latest Pi’s versions.

Example to build for aarch64:

I’m a bit confused about the nixos-anywhere here.

For my Pis I just used to build a custom image and then flash that to an SD card.
For updates I built them on my laptop and pushed them to the Pi’s with simple nixos-rebuild

However I stopped doing it this way because I wanted to encrypt the SD card and now use UEFI on the Pis and install NixOS like on any other computer.
The updates can still work in the same way but I’ve enabled automatic updates on the Pis and they rebuild themselves during the night.
A Pi with 4GB RAM plus Swap should be enough depending on your setup.

In the past we had rasbian kernels not having support for kexec. Otherwise nixos-anywhere also works fine on aarch64.

1 Like