Installing NixOS on a remote machine is complicated and time-consuming. The nixos-anywhere tool allows you to access a remote computer via SSH, partition and format its disks, and install NixOS quickly and painlessly.
Since nixos-anywhere makes use of stored configurations, you can repeat the same installation as often as you need, using a single command for each target machine.
The configuration can specify software packages to include in the build, and additional files can optionally be copied to the new machine. WIth nixos-anywhere it's therefore possible to set up a complete working system remotely with a single command.
Nixos-anywhere can be used equally well for cloud servers, bare metal servers such as Hezner, and local servers accessible via a LAN. You can create standard configurations, and use the same configuration to create identical servers anywhere.
It's extremely useful in situations where you have servers on AWS or Google, and aso on physical machines either locally or hosted on a service provider, and you need a common solution that works anywhere.
The partitioning and formatting options are specified in a NixOS configuration. 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
-
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 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, using a normal Nixos installer image. This feature is described in the user guide, and is useful because you can pre-configure your required software and preferences, and build the new machine with a single command.
Important Note: Do not use a production server as the target, as it will be completely overwritten and all data lost. This tool should only be used for commissioning a new server, or repurposing an old server that contains no data that needs to be retained.
-
Source Machine:
- Can be any Linux or Mac server with Nix installed, or a NixOS server.
-
Destination Machine:
-
Must be an x86-64 machine
-
Unless you are using the feature to install from a Nixos installer image, it must be running x86-64 Linux with
kexec
support . Most x86_64 Linux systems do havekexec
support. -
Must have at least 2.5 GB of RAM, excluding swap.
-
The tool does not need to be installed, since it can be run directly from this repository.
First create a repo that includes the disk configuration and a flake that configures options. Samples of the disk configuration and flake are included in the documentation. Full details of the configuration and the flake are given in the reference manual.
Once you have created these, you can run the tool with a single nix run
command, which may look like this:
nix run github:numtide/nixos-anywhere -- --flake github:JillThornhill/flakes-example#hetzner-cloud [email protected]
The Quickstart Guide gives full information on how to run nixos-anywhere in its simplest form. For more specific instructions to suit individual requirements, see the User Guide.
This software is provided free under the MIT Licence.
If you would like to become a contributor, please see our contribution guidelines
This software is brought to you courtesy of Numtide Consulting.
Numtide offers experienced consultants for hire, specializing in the following areas:
(Need a list of services)