Install NixOS on Scaleway X86 Virtual Cloud Server

From NixOS Wiki
Revision as of 10:32, 1 December 2017 by imported>Fadenb (Created page with " == Preparation == === Build NixOS kexec package === * git clone https://github.com/cleverca22/nix-tests.git * cd nix-tests/kexec/ * Edit configuration.nix according to your n...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Preparation

Build NixOS kexec package

# new cmd: nix-build '<nixpkgs/nixos>' -A config.system.build.kexec_tarball -I nixos-config=./configuration.nix -Q -j 4

{ lib, pkgs, config, ... }:

with lib;

{
  imports = [ <nixpkgs/nixos/modules/installer/netboot/netboot-minimal.nix> ./kexec.nix ./justdoit.nix ];

  #boot.supportedFilesystems = [ "zfs" ];
  boot.loader.grub.enable = false;
  boot.kernelParams = [
    "console=ttyS0,115200"          # allows certain forms of remote access, if the hardware is setup right
    "panic=30" "boot.panic_on_fail" # reboot the machine upon fatal boot issues
  ];
  systemd.services.sshd.wantedBy = mkForce [ "multi-user.target" ];
  networking.hostName = "kexec";
  # example way to embed an ssh pubkey into the tar
  users.users.root.openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3.... Your-SSH-key" ];
}
  • Build kexec package like shown at the beginning of the file:
nix-build '<nixpkgs/nixos>' -A config.system.build.kexec_tarball -I nixos-config=./configuration.nix -Q -j 4

Create Scaleway Instance

  • Open Scaleway "Create a server" page
  • Enter name
  • Select region
  • Select server type
    • This will only work for the V and X types of servers (e.g. VC1M or X64-15GB)
    • I selected a VC1M for the rest of this guide
  • Select "Debian Sid" from the distributions tab
    • At the time of writing of this guide the Ubuntu Xenial did not have a kexec enabled kernel
  • create server
  • wait until server has been provisioned and is done booting
    • Can be checked by looking at the console

Start NixOS kexec system

  • copy the results of the nix-build to the server
scp result/tarball/nixos-system-x86_64-linux.tar.xz root@51.YY.XX.93:
  • ssh into the server
  • extract the tarball into /
cd /
tar -xf /root/nixos-system-x86_64-linux.tar.xz
  • execute the kexec_nixos script ./kexec_nixos
  • You should see output like this:
root@scalenix:/# ./kexec_nixos 
++ mktemp -d
+ cd /tmp/tmp.iDXuzu8Ec4
+ pwd
/tmp/tmp.iDXuzu8Ec4
+ mkdir initrd
+ pushd initrd
/tmp/tmp.iDXuzu8Ec4/initrd /tmp/tmp.iDXuzu8Ec4
+ cat /ssh_pubkey
cat: /ssh_pubkey: No such file or directory
+ find -type f
+ cpio -o -H newc
+ gzip -9
1 block
+ popd
/tmp/tmp.iDXuzu8Ec4
+ cat /nix/store/2lmw78k2ralvpn6fa270b53nz1xgqk8b-image/initrd extra.gz
+ kexec -l /nix/store/2lmw78k2ralvpn6fa270b53nz1xgqk8b-image/kernel --initrd=final.gz '--append=init=/nix/store/sv9hndbkrdxr1psi2jr82hkm1ba0j8bx-nixos-system-kexec-17.09.git.f3841ab/init loglevel=4 console=ttyS0,115200 panic=30 boot.panic_on_fail'
+ sync
+ echo 'executing kernel, filesystems will be improperly umounted'
executing kernel, filesystems will be improperly umounted
+ kexec -e
packet_write_wait: Connection to 51.15.71.93 port 22: Broken pipe
  • Once the ssh connection is broken take a look at the servers console in the webinterface