NixOS Installation Guide: Difference between revisions

From NixOS Wiki
imported>Fadenb
m →‎Special hardware: fix internal wiki link
imported>Fadenb
Line 5: Line 5:
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 <code>configuration.nix</code> which is used to build the 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 <code>configuration.nix</code> which is used to build the image


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


   # enable sshd on boot
   # enable sshd on boot
Line 21: Line 22:
   # the following allows to embed your own ssh key into the image
   # the following allows to embed your own ssh key into the image
   users.extraUsers.root.openssh.authorizedKeys.keys = [
   users.extraUsers.root.openssh.authorizedKeys.keys = [
     &quot;ssh-ed25519 AaAeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee username@host&quot;
     "ssh-ed25519 AaAeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee username@host"
   ];
   ];


Line 30: Line 31:
   #  usePredictableInterfaceNames = false;
   #  usePredictableInterfaceNames = false;
   #  interfaces.eth0.ip4 = [{
   #  interfaces.eth0.ip4 = [{
   #    address = &quot;64.137.201.46&quot;;
   #    address = "64.137.201.46";
   #    prefixLength = 24;
   #    prefixLength = 24;
   #  }];
   #  }];
   #  defaultGateway = &quot;64.137.201.1&quot;;
   #  defaultGateway = "64.137.201.1";
   #  nameServers = [ &quot;8.8.8.8&quot; ];
   #  nameServers = [ "8.8.8.8" ];
   #};
   #};


}</pre>
}</syntaxhighlight>
The '''full path''' of the file needs to be passed to <code>nix-build</code>.
The '''full path''' of the file needs to be passed to <code>nix-build</code>.


<pre>$ nix-build '&lt;nixpkgs/nixos&gt;' -A config.system.build.isoImage -I nixos-config=/etc/nixos/myiso.nix</pre>
<syntaxhighlight lang="bash">$ nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=/etc/nixos/myiso.nix</syntaxhighlight>
The resulting image can be found in <code>result</code>:
The resulting image can be found in <code>result</code>:


<pre>$ ls result/iso/
<syntaxhighlight lang="bash">$ ls result/iso/
nixos-17.09.git.158ec57-x86_64-linux.iso</pre>
nixos-17.09.git.158ec57-x86_64-linux.iso</syntaxhighlight>
 
== Install Nixos on VPS/Cloud-Provider ==
== Install Nixos on VPS/Cloud-Provider ==



Revision as of 19:58, 22 August 2017

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