Installing NixOS

From BitFolk
Jump to navigation Jump to search
Warning Warning: This guide assumes that you’re already comfortable with Nix and NixOS.

Installation

The basic idea of this installation mode is to install NixOS from the rescue system. Since this system has very limited resources available, the system closure is built elsewhere and copied over.

Partitioning & Mounts

Like in a standard NixOS installation, prepare by partitioning your disks as desired.

If you place your /nix folder on a separate disk, you may want to consider mounting this disk in the rescue system and the /mnt/nix path for the target system. This will also avoid issues with the rescue system running out of space when copying the system closure.

Note that your target system's /boot directory should be on a filesystem that BitFolk supports for booting. At the time of writing (February 2022) this means ext*, xfs or btrfs. Here we'll use ext4 for the /mnt/boot location. BitFolk will boot your Nix-created GRUB configuration directly from there.

Installing Nix itself

To perform the installation you will need Nix. The rescue image is a Debian system, and Nix is available as a Debian package.

Ensure that your /nix is mounted correctly (if desired) and run apt update && apt install nix.

You should then set up a Nix channel or other nixpkgs source as desired and install nixpkgs.nixos-install-tools, which will give you the standard installation tooling.

Prepare NixOS configuration

Prepare your NixOS configuration by running nixos-generate-config --root /mnt as normal. Copy the generated configuration files to the machine on which you want to perform the initial build and perform necessary edits.

Some recommended changes:

  1. Set boot.loader.grub.device = "nodev";. This way a GRUB configuration will be generated, but GRUB itself will not be installed - which is exactly what is needed on BitFolk.
  2. Skip DHCP setup and configure interfaces.<if>.{ipv4,ipv6} directly.
  3. Don't forget to enable SSH & configure your user access.

Install NixOS

Build the system closure on your local machine using whatever way you prefer.

Once the build is completed, copy the closure to the rescue VM using nix copy --to ssh://root@<your-rescue-vm> /nix/store/path-to-system-closure. Note that this requires SSH credentials for root to be set up, or the other rescue VM user to be added to Nix's trusted user set.

Note Note: You can use standard NixOS deployment tools like morph to do this, too.

You can now perform the actual installation from the rescue VM by using nixos-install --root /mnt --system /nix/store/path-to-system-closure.

If this completes successfully, you can exit the rescue VM (by pressing ^] in the Xen Shell) and reboot. Don't worry, if you messed up some network configuration accidentally the Xen Shell will let you easily attach to the machine's console and fix it.

That's it!

Example configurations

Check out the example NixOS configurations of Alyssa (as well as her BitFolk module) and TVL.