Home

Awesome

NixOS-Infect

What is this?

A script to install NixOS on non-NixOS hosts.

NixOS-Infect is so named because of the high likelihood of rendering a system inoperable. Use with extreme caution and preferably only on newly provisioned systems.

This script has successfully been tested on at least the follow hosting providers and plans:

Should you find that it works on your hoster, feel free to update this README and issue a pull request.

Motivation

Motivation for this script: nixos-assimilate should supplant this script entirely, if it's ever completed. nixos-in-place was quite broken when I tried it, and also took a pretty janky approach that was substantially more complex than this (although it supported more platforms): it didn't install to root (/nixos instead), left dregs of the old filesystem (almost always unnecessary since starting from a fresh deployment), and most importantly, simply didn't work for me! (old system was being because grub wasnt properly reinstalled)

How do I use it?

  1. Read and understand the the script
  2. Deploy any custom configuration you want on your host
  3. Deploy your host as non-Nix Operating System.
  4. Deploy an SSH key for the root user.

NB: This step is important. The root user will not have a password when nixos-infect runs to completion. To enable root login, you must have an SSH key configured.

  1. run the script with:
  curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-23.05 bash -x

NB: This script wipes out the targeted host's root filesystem when it runs to completion. Any errors halt execution. A failure will leave the system in an inconsistent state, and so it is advised to run with bash -x.

Hoster notes:

Digital Ocean

You may utilize Digital Ocean's "user data" mechanism (found in the Web UI or HTTP API), and supply to it the following example yaml stanzas:

#cloud-config

runcmd:
  - curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | PROVIDER=digitalocean NIX_CHANNEL=nixos-23.05 bash 2>&1 | tee /tmp/infect.log

Potential tweaks:

#cloud-config
write_files:
- path: /etc/nixos/host.nix
  permissions: '0644'
  content: |
    {pkgs, ...}:
    {
      environment.systemPackages = with pkgs; [ vim ];
    }
runcmd:
  - curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | PROVIDER=digitalocean NIXOS_IMPORT=./host.nix NIX_CHANNEL=nixos-23.05 bash 2>&1 | tee /tmp/infect.log

Tested on

DistributionNameStatustest date
CentOS6.9 x32failure2020-03-30
CentOS6.9 x64failure2020-03-30
CentOS7.6 x64failure2020-03-30
CentOS8.1 x64success2020-03-30
CoreOS2345.3.0 (stable)unable2020-03-30
CoreOS2411.1.0 (beta)unable2020-03-30
CoreOS2430.0.0 (alpha)unable2020-03-30
Debian10.3 x64success2020-03-30
Debian9.12 x64success2020-03-30
Debian11 x64success2023-11-12
Fedora30 x64success2020-03-30
Fedora31 x64success2020-03-30
FreeBSD11.3 x64 ufsfailure2020-03-30
FreeBSD11.3 x64 zfsfailure2020-03-30
FreeBSD12.1 x64 ufsfailure2020-03-30
FreeBSD12.1 x64 zfsfailure2020-03-30
RancherOSv1.5.5unable2020-03-30
Ubuntu16.04.6 (LTS) x32success2020-03-30
Ubuntu16.04.6 (LTS) x64success2020-03-30
Ubuntu18.04.3 (LTS) x64success2020-03-30
Ubuntu19.10 x64success2020-03-30
Ubuntu20.04 x64success2022-03-23
Ubuntu22.04 x64success2023-06-05
Ubuntu22.10 x64failure2023-06-05
Ubuntu23.10 x64failure2023-11-16

Vultr

To set up a NixOS Vultr server, instantiate an Ubuntu box with the following "Cloud-Init User-Data":

#!/bin/sh

curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-23.05 bash

Allow for a few minutes over the usual Ubuntu deployment time for NixOS to download & install itself.

Tested on

DistributionNameStatustest date
Ubuntu18.10 x64success(Unknown)
Ubuntu22.04 x64success2022-07-04

Hetzner cloud

Hetzner cloud works out of the box. When creating a server provide the following yaml as "Cloud config":

#cloud-config

runcmd:
  - curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | PROVIDER=hetznercloud NIX_CHANNEL=nixos-23.05 bash 2>&1 | tee /tmp/infect.log

Tested on

DistributionNameStatustest date
Debian11success2023-04-29
Debian12 aarch64success2023-09-02
Ubuntu20.04 x64success(Unknown)
Ubuntu22.04 x64success2023-04-29
Ubuntu22.04 aarch64success2023-04-16

InterServer VPS

Tested on

DistributionNameStatustest date
Debian9success2021-01-29
Debian10success2021-01-29
Ubuntu20.04success2021-01-29
Ubuntu18.04success2021-01-29
Ubuntu14.04success2021-01-29

Tencent Cloud Lighthouse

Tencent Cloud Lighthouse Hong Kong Region Works out of the box.

Other Regions in China may not work because of the unreliable connection between China and global Internet or GFW.

Tested on

DistributionNameStatustest date
Debian10success2021-03-11

OVHcloud

Before executing the install script, you may need to check your mounts with df -h. By default, OVH adds a relatively short in memory tmpfs mount on the /tmp folder, so the install script runs short in memory and fails. Just execute umount /tmp before launching the install script. Full install process described here

DistributionNameStatustest date
Arch LinuxArch Linux x86-64success2021-03-25
Debian10success2021-04-29
Debian11success2021-11-17
Ubuntu22.04success2022-06-19
Ubuntu23.04Fails2023-06-01

The 23.04 Ubuntu distribution fails to boot, due to the following error:

/dev/sda1 has unsupported feature(s): FEATURE_C12

e2fsck: Get a newer version of e2fsck

Using an older Ubuntu version fixes this issue.

Oracle Cloud Infrastructure

Tested for both VM.Standard.E2.1.Micro (x86) and VM.Standard.A1.Flex (AArch64) instances.

Tested on

DistributionNameStatustest dateShape
Oracle Linux7.9success2021-05-31
Ubuntu20.04success2022-03-23
Ubuntu20.04success2022-04-19free arm
Oracle Linux8.0-failure-2022-04-19free amd
CentOS8.0-failure-2022-04-19free amd
Oracle Linux7.9[1]success2022-04-19free amd
Ubuntu22.04success2022-11-13free arm
Oracle Linux9.1[2]success2023-03-29free arm
Oracle Linux8.7[3]success2023-06-06free amd
AlmaLinux OS9.2.20230516success2023-07-05free arm
[1] The Oracle 7.9 layout has 200Mb for /boot 8G for swap
PR#100 Adopted 8G Swap device
[2] OL9.1 had 2GB /boot, 100MB /boot/efi (nixos used as /boot) and swapfile
[3] Both 22.11 and 23.05 failed to boot, but installing 22.05 and then upgrading
worked out as intended.

Aliyun ECS

Aliyun ECS tested on ecs.s6-c1m2.large, region cn-shanghai, needs a few tweaks:

Tested on

DistributionNameStatustest date
Ubuntu20.04success2021-12-28
Ubuntu22.04success2023-04-05

GalaxyGate

Tested on

DistributionNameStatustest date
Ubuntu20.04success2022-04-02

Cockbox

Requred some Xen modules to work out, after that NixOS erected itself without a hinch.

Tested on

DistributionNameStatustest date
Ubuntu20.04success2022-06-12

Google Cloud Platform

Tested on

DistributionNameStatustest dateMachine type
Debian11success2023-11-12ec2-micro
Debian (Amd64)11success2023-11-12
Ubuntu on Ampere Altra (Arm64)20.04success2022-09-07
Ubuntu20.04success2022-09-07Ampere Ultra
Ubuntu20.04-failure-2023-11-12ec2-micro

Contabo

Tested on Cloud VPS. Contabo sets the hostname to something like vmi######.contaboserver.net, Nixos only allows RFC 1035 compliant hostnames (see here). Run hostname something_without_dots before running the script. If you run the script before changing the hostname - remove the /etc/nixos/configuration.nix so it's regenerated with the new hostname.

Tested on

DistributionNameStatustest date
Ubuntu22.04success2022-09-26

Liga Hosting

Liga Hosting works without any issue. You'll need to add your ssh key to the host either during build time or using ssh-copy-id before running nixos-infect

#!/bin/sh

curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-23.05 bash 2>&1 | tee /tmp/infect.log

Tested on

DistributionNameStatustest date
Debian11success2022-12-01
Ubuntu20.04success2022-12-01
Ubuntu22.04success2022-12-01

AWS Lightsail

Make sure to set PROVIDER="lightsail".

Setting a root ssh key manually is not necessary, the key provided as part of the instance launch process will be used.

If you run into issues, debug using the most similar ec2 instance that is on the Nitro platform. Nitro platform instances have a serial console that allow you to troubleshoot boot issues, and Lightsail instances are just EC2 with a different pricing model and UI.

Windcloud

Tested on vServer. The network configuration seems to be important so the same tweaks as for DigitalOcean are necessary (see above).

Tested on

DistributionNameStatustest date
Ubuntu20.04success2022-12-09

ServArica

Requires the same static network settings that Digital Ocean does.

curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | PROVIDER=servarica NIX_CHANNEL=nixos-23.05 bash

Tested on

DistributionNameStatustest date
Debian11.4success2022-12-12
Ubuntu20.04success2022-11-26

Clouding.io

I could not get it to run via UserData scripts, but downloading and executing the script worked flawlessly.

Tested on

DistributionNameStatustest date
Debian11success2022-12-20

Scaleway

As of November 2020, it is easy to get a NixOS VM running on Scaleway by using nixos-infect and Scaleway's support for cloud init. All that is needed is to follow the nixos-infect recipe for Digital Ocean, removing the Digital Ocean-specific stuff. So, pragmatically, start an Ubuntu or Fedora VM and use something like the following as your cloud-init startup script:

#cloud-config
write_files:
- path: /etc/nixos/host.nix
  permissions: '0644'
  content: |
    {pkgs, ...}:
    {
      environment.systemPackages = with pkgs; [ tmux ];
    }
runcmd:
  - curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect |  NIXOS_IMPORT=./host.nix NIX_CHANNEL=nixos-23.05 bash 2>&1 | tee /tmp/infect.log

Tested on

DistributionNameStatustest date
Ubuntu20.04success2020-11-??

RackNerd

Remember that the SSH keys are not automatically generated/uploaded, so you need to create them as usual with ssh-keygen or some other means, add the public key to the .ssh/authorized_keys file on the remote host, and have a copy of the private key on your local box.

On RackNerd's Ubuntu 20.04, there's no curl by default, so wget -O- needs to be used instead:

# wget -O- https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-23.05 bash -x

Tested on

DistributionNameStatustest date
AlmaLinux8failure (tar missing)2023-08-29
Ubuntu20.04success2023-08-29