NixOS Installation Guide

From NixOS Wiki
Revision as of 18:14, 21 August 2017 by imported>Makefu (initial batch of nixos-users)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

For commodity PC hardware the official manual should covers the most use cases.

Build a custom installation image

NixOS provides an easy way to build a custom variant of the installation image. This might be useful to embed your own ssh key or enable additional features like zfs support. It allows to specify a custom configuration.nix which is used to build the image

# myiso.nix
{ config, lib, pkgs, modulesPath, ... }:
{
   imports = [
     <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
   ];
   # enable zfs support
   #boot.supportedFilesystems = [ "zfs" ];

   # enable sshd on boot
   services.openssh = {
     enable = true;
     startWhenNeeded = true;
   };
   # the following allows to embed your own ssh key into the image
   users.extraUsers.root.openssh.authorizedKeys.keys = [
     "ssh-ed25519 AaAeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee username@host"
   ];

   ## The following snippet is useful, when static ip addresses are required,
   ## e.g. for VPS installation
   #
   #networking = {
   #  usePredictableInterfaceNames = false;
   #  interfaces.eth0.ip4 = [{
   #    address = "64.137.201.46";
   #    prefixLength = 24;
   #  }];
   #  defaultGateway = "64.137.201.1";
   #  nameServers = [ "8.8.8.8" ];
   #};

}

The full path of the file needs to be passed to nix-build.

$ nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=/etc/nixos/myiso.nix

The resulting image can be found in result:

$ ls result/iso/
nixos-17.09.git.158ec57-x86_64-linux.iso

Install Nixos on VPS/Cloud-Provider

Not all providers allow to upload own images or provide NixOS images for installation. However there are a few ways to install NixOS anyhow.

nixos-in-place and nixos-infect are generic approaches to install NixOS from an existing Linux.

A different approach is to build an kexec-based image to start the installer from an booted linux as shown in this repo

Installation Stories

Add the code you needed to run in order to deploy NixOS at $provider .

Hetzner

Hetzner provides an interface to upload your own ISO-images. However you may want to build your own iso-image, which has openssh with ssh keys due the lack of a remote console. An easier method to install NixOS on Hetzner, is to use the existing integration into NixOps

Digitalocean

On Digitalocean the project nixos-infect can be used to transform an existing installation into NixOS. This method will be also used in NixOps.

Netcup

You can mount your own images similar to hetzner, see the official netcup documentation.

Linode

NixOS is official supported by Linode. Up to date documentation can be obtained from their manual

CloudAtCost

Scaleway

The kexec method above works well, but bear in mind it only works with the 'virtual' class of servers, as they run under a hypervisor which attaches the disks before the kernel boots. The 'bare-metal' servers rely on a special Linux kernel booting to attach network /dev/nbdX drives which works only with Scaleway supplied images.

<your vps provider here>

Special hardware

  • Blog post how to install NixOS on a Dell 9560
  • for embedded Hardware like the Raspberry Pi2 see NixOS-on-ARM