This repository has been updated by @jr551, who merged contributions from several pull requests that had been pending approval. These contributions include important fixes, documentation updates, and support for additional hosting providers. A big thanks to all the contributors who made these improvements possible!
If you find that it works on your hoster, feel free to update this README and issue a pull request.
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 the following hosting providers and plans:
- DigitalOcean
- Hetzner Cloud
- Vultr
- Interserver VPS
- Tencent Cloud Lighthouse
- OVHcloud
- Oracle Cloud Infrastructure
- GalaxyGate
- Cockbox
- Google Cloud Platform
- Contabo
- Liga Hosting
- AWS Lightsail
- Windcloud
- Clouding.io
- Scaleway
- RackNerd
If you find that it works on your hoster, feel free to update this README and issue a pull request.
The motivation for this script is to provide a simpler and more reliable method for installing NixOS on existing systems compared to alternatives like nixos-assimilate
and nixos-in-place
. The latter were either incomplete, overly complex, or failed to work reliably in various scenarios.
-
Read and understand the script.
-
Deploy any custom configuration you want on your host.
-
Deploy your host as a non-Nix Operating System.
-
Deploy an SSH key for the root user.
NB: This step is crucial. The root user will not have a password when
nixos-infect
completes. To enable root login, you must have an SSH key configured. If a custom SSH port is used, it will be reverted back to 22. -
Run the script with:
curl https://raw.githubusercontent.com/jr551/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-25.05 bash -x
NB: This script wipes out the targeted host's root filesystem upon completion. Any errors will halt execution, potentially leaving the system in an inconsistent state. It is advised to run with
bash -x
for debugging purposes.
You can utilize DigitalOcean's "user data" mechanism (available in the Web UI or via the HTTP API) by supplying the following example YAML stanzas:
#cloud-config
runcmd:
- curl https://raw.githubusercontent.com/jr551/nixos-infect/master/nixos-infect | PROVIDER=digitalocean NIX_CHANNEL=nixos-25.05 bash 2>&1 | tee /tmp/infect.log
- Configuration Files:
/etc/nixos/{,hardware-}configuration.nix
: Rudimentary mostly static config./etc/nixos/networking.nix
: Networking settings determined at runtime. Tweak if no IPv6, different number of adapters, etc.
#cloud-config
write_files:
- path: /etc/nixos/host.nix
permissions: '0644'
content: |
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [ vim ];
}
runcmd:
- curl https://raw.githubusercontent.com/jr551/nixos-infect/master/nixos-infect | PROVIDER=digitalocean NIXOS_IMPORT=./host.nix NIX_CHANNEL=nixos-25.05 bash 2>&1 | tee /tmp/infect.log
Distribution | Name | Status | Test Date |
---|---|---|---|
CentOS | 6.9 x32 | failure | 2020-03-30 |
CentOS | 6.9 x64 | failure | 2020-03-30 |
CentOS | 7.6 x64 | failure | 2020-03-30 |
CentOS | 8.1 x64 | success | 2020-03-30 |
Contributions are welcome! If you find that the script works on your hosting provider, please update this README and submit a pull request. Ensure to include relevant details and test results to help others benefit from your improvements.
Use NixOS-Infect at your own risk. This script can render your system inoperable. It is recommended to use it only on newly provisioned systems or environments where data loss is acceptable.
This project is licensed under the MIT License.
Special thanks to all contributors and the NixOS community for their continuous support and enhancements.