Here’s an easy way to get a NixOS node spun up using nixos-infect.

1) Set up a new droplet

  • Choose Ubuntu 22.04
  • Add SSH keys for something you have a local IdentityFile for.
  • Under “Advanced Options” -> “Add initialization scripts” paste
#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-25.05 bash 2>&1 | tee /tmp/infect.log

2) SSH in and copy config down

Add the node’s SSH config to ~/.ssh/config

Host [node-name]
        HostName [IP-address]
        User root
        IdentityFile ~/.ssh/[identity]

Now you should be able to ssh [node-name] and cat /etc/nixos/configuration.nix to see your new system.

Start a new directory for containing the node’s configuration locally. Maybe call it [node-name]-deployment.

On the server, run scp [node-name]:/etc/nixos/* ..

Now you’ve got the remote configuration in hand. If you wanted to alter the node, the naive way to do it is edit the configuration, push it back over, and run sudo nixos-rebuild switch. But there’s a better way to approach this that involves building the system locally. We’ll continue in setting up deploy-rs.