NixOS Anywhere

Village: NixOS


Like every C3 event, there are many organized, talks, sessions, workshops, ... to attend. Browse the list and find interesting stuff.

Setting up a new machine is time-consuming, and becomes complicated when it needs to be done remotely. If you're installing NixOS, the nixos-anywhere (formerly known as nixos-remote) tool allows you to pre-configure the whole process including:

Disk partitioning and formatting
Configuring and installing NixOS
Installing additional files and software

You can then initiate an unattended installation with a single CLI command. Since nixos-anywhere can access the new machine using SSH, it's ideal for remote installations.

Once you have initiated the command, there is no need to 'babysit' the installation. It all happens automatically.

You can use the stored configuration to repeat the same installation if you need to.

Overview 🔗

If you have machines on a mix of platforms, you'll need a common installation solution that works anywhere. nixos-anywhere is ideal in this situation.

nixos-anywhere can be used equally well for cloud servers, bare metal servers such as Hetzner, and local servers accessible via a LAN. You can create standard configurations, and use the same configuration to create identical servers anywhere.

You first create Nix configurations to specify partitioning, formatting and NixOS configurations. Further options can be controlled by a flake and by run-time switches.

Once the configuration has been created, a single command will:

Connect to the remote server via SSH
Detect whether a NixOS installer is present; if not, it will use the Linux kexec tool to boot into a Nixos installer.
Use the disko tool to partition and format the hard drive
Install NixOS
Optionally install any Nix packages and other software required.
Optionally copy additional files to the new machine

It's also possible to use nixos-anywhere to simplify the installation on a machine that has no current operating system, first booting from a NixOS installer image. This feature is described in the how-to guide. It's useful because you can pre-configure your required software and preferences, and build the new machine with a single command.

Important Note: Never use a production server as the target. It will be completely overwritten and all data lost. This tool should only be used for commissioning a new computer or repurposing an old machine once all important data has been migrated.


Links

Archived page - Impressum/Datenschutz