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:
<div class="codehilite"><span></span>Disk partitioning and formatting
Configuring and installing NixOS
Installing additional files and software
</div>
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:
<div class="codehilite"><span></span><span class="n">Connect</span><span class="w"> </span><span class="n">to</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="k">remote</span><span class="w"> </span><span class="n">server</span><span class="w"> </span><span class="n">via</span><span class="w"> </span><span class="n">SSH</span>
<span class="n">Detect</span><span class="w"> </span><span class="n">whether</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">NixOS</span><span class="w"> </span><span class="n">installer</span><span class="w"> </span><span class="k">is</span><span class="w"> </span><span class="n">present</span><span class="p">;</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="ow">not</span><span class="p">,</span><span class="w"> </span><span class="n">it</span><span class="w"> </span><span class="n">will</span><span class="w"> </span><span class="n">use</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">Linux</span><span class="w"> </span><span class="n">kexec</span><span class="w"> </span><span class="k">tool</span><span class="w"> </span><span class="n">to</span><span class="w"> </span><span class="n">boot</span><span class="w"> </span><span class="n">into</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">Nixos</span><span class="w"> </span><span class="n">installer</span><span class="o">.</span>
<span class="n">Use</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">disko</span><span class="w"> </span><span class="k">tool</span><span class="w"> </span><span class="n">to</span><span class="w"> </span><span class="n">partition</span><span class="w"> </span><span class="ow">and</span><span class="w"> </span><span class="n">format</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">hard</span><span class="w"> </span><span class="n">drive</span>
<span class="n">Install</span><span class="w"> </span><span class="n">NixOS</span>
<span class="n">Optionally</span><span class="w"> </span><span class="n">install</span><span class="w"> </span><span class="n">any</span><span class="w"> </span><span class="n">Nix</span><span class="w"> </span><span class="n">packages</span><span class="w"> </span><span class="ow">and</span><span class="w"> </span><span class="n">other</span><span class="w"> </span><span class="n">software</span><span class="w"> </span><span class="n">required</span><span class="o">.</span>
<span class="n">Optionally</span><span class="w"> </span><span class="n">copy</span><span class="w"> </span><span class="n">additional</span><span class="w"> </span><span class="n">files</span><span class="w"> </span><span class="n">to</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">new</span><span class="w"> </span><span class="n">machine</span>
</div>
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
- website: official website
- website: official website