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

install nix

bash <(curl -L
. $HOME/.nix-profile/etc/profile.d/
sudo nix-channel --add nixpkgs

setup nixpkgs

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

Now partition the disks the way you want them and mount them to /mnt

mount /dev/sda1 /mnt

nextup generate config

nixos-generate-config --root /mnt

make sure these lines are included in your config:

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

  boot.initrd = {
    availableKernelModules = [
      "virtio_pci"  # disk
      "virtio_scsi" # disk
    kernelModules = [

install NixOS


then exit xuser and reboot


after rebooting make sure the nix-channels are up-to-date

nix-channel --add nixos
nixos-rebuild switch --upgrade