Install NixOS on a Contabo-VPS

this little guide describes how to bootstrap nix to install nixos on a contabo-vps server:

create /nix and used tempfs, because otherwise the disk is full quickly

mkdir /nix
mount -t tmpfs tmpfs /nix -o size=5g

create nix-build users

groupadd nixbld
for n in $(seq 1 10); do useradd -c "Nix build user $n" -d /var/empty -g nixbld -G nixbld -M -N -r -s "$(command -v nologin)" "nixbld$n"; done

change password of xuser (so we can use sudo later) and switch to it

passwd xuser
su xuser
cd

install nix

bash <(curl -L https://nixos.org/nix/install)
. $HOME/.nix-profile/etc/profile.d/nix.sh
sudo nix-channel --add https://nixos.org/channels/nixos-20.03 nixpkgs

setup nixpkgs

sudo -E nix-env -iE "_: with import <nixpkgs/nixos> { configuration = {}; }; with config.system.build; [ nixos-generate-config nixos-install nixos-enter manual.manpages ]"

clone config repo

git clone https://github.com/Amani-Kinderdorf/nixos.git
cd nixos

make sure to include this config:

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

{
  boot.initrd = {
    availableKernelModules = [
      "virtio_pci"  # disk
      "virtio_scsi" # disk
    ];
    kernelModules = [
      "dm-snapshot"
    ];
  };
}

wipe disks and install from scratch

sudo -E ./install.sh

then exit xuser and reboot

exit
reboot

after rebooting update nix-channels

nix-channel --add https://nixos.org/channels/nixos-20.03 nixos
nixos-rebuild switch --upgrade