Return Home

🚀 Deploying a Custom NixOS Image on DigitalOcean

📌 Step 1: Create a DigitalOcean VM

  1. Log into DigitalOcean
  2. Navigate to DropletsCreate Droplet
  3. Choose Ubuntu 22.04 (or any Linux distro)
  4. Select the cheapest plan (e.g., $6/mo shared CPU)
  5. Choose a datacenter region
  6. Set up SSH access
  7. 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

  1. Copy the default NixOS config:
    cp -r /etc/nixos /mnt/nixos/
    
  2. Modify /mnt/nixos/configuration.nix to suit your needs.
  3. Unmount:
    umount /mnt/nixos
    
  4. Compress the image:
    gzip nixos.img
    

📌 Step 4: Upload to DigitalOcean Spaces

  1. Create a Spaces Bucket in DigitalOcean.
  2. Install s3cmd:
    apt install s3cmd
    
  3. Configure it:
    s3cmd --configure
    
  4. Upload the image:
    s3cmd put nixos.img.gz s3://your-space-name/
    

📌 Step 5: Create a Custom Snapshot in DigitalOcean

  1. Go to ImagesCustom Images
  2. Click Import Image
  3. Paste the public URL of nixos.img.gz
  4. Click Start Import and wait for completion

🎉 Step 6: Deploy Your NixOS Droplet!

  1. Go to DropletsCreate Droplet

  2. Select Custom Images
  3. Choose your NixOS image
  4. Set up networking & SSH
  5. Click Create

✅ BOOOYAH! NixOS is now running on DigitalOcean! 🚀

Return Home