🚀 Deploying a Custom NixOS Image on DigitalOcean
📌 Step 1: Create a DigitalOcean VM
- Log into DigitalOcean
- Navigate to Droplets → Create Droplet
- Choose Ubuntu 22.04 (or any Linux distro)
- Select the cheapest plan (e.g., $6/mo shared CPU)
- Choose a datacenter region
- Set up SSH access
- Click Create Droplet
📌 Step 2: Prepare the VM for NixOS Installation
SSH into the newly created droplet:
ssh root@your-droplet-ip
Update and install necessary packages:
apt update && apt install -y parted wget
Download the latest NixOS minimal ISO:
wget https://channels.nixos.org/nixos-24.11/latest-nixos-minimal-x86_64-linux.iso -O nixos.iso
📌 Step 3: Create a NixOS Image
Create a raw disk image:
dd if=/dev/zero of=nixos.img bs=1G count=8 # Adjust size as needed
mkfs.ext4 nixos.img # Format the image
Mount and install NixOS:
mkdir /mnt/nixos
mount -o loop nixos.img /mnt/nixos
# Download and extract the NixOS ISO contents here
Configure NixOS
- Copy the default NixOS config:
cp -r /etc/nixos /mnt/nixos/
- Modify
/mnt/nixos/configuration.nix
to suit your needs. - Unmount:
umount /mnt/nixos
- Compress the image:
gzip nixos.img
📌 Step 4: Upload to DigitalOcean Spaces
- Create a Spaces Bucket in DigitalOcean.
- Install
s3cmd
:apt install s3cmd
- Configure it:
s3cmd --configure
- Upload the image:
s3cmd put nixos.img.gz s3://your-space-name/
📌 Step 5: Create a Custom Snapshot in DigitalOcean
- Go to Images → Custom Images
- Click Import Image
- Paste the public URL of
nixos.img.gz
- Click Start Import and wait for completion
🎉 Step 6: Deploy Your NixOS Droplet!
-
Go to Droplets → Create Droplet
- Select Custom Images
- Choose your NixOS image
- Set up networking & SSH
- Click Create