Deployment Images Guide

This NixOS template includes comprehensive deployment image generation using our deployment factory, providing ready-to-deploy images for various platforms and use cases through a modular, unified system.

Quick Start

Build a specific image

# Cloud deployment images
nix build .#aws              # Amazon EC2 AMI
nix build .#azure            # Microsoft Azure VHD
nix build .#digitalocean     # Digital Ocean Droplet

# Virtualization images
nix build .#vmware           # VMware VM
nix build .#virtualbox-desktop # VirtualBox OVA with desktop
nix build .#qemu             # QEMU/KVM QCOW2

# Container images
nix build .#lxc              # LXC container

# Installation media
nix build .#iso              # Bootable live ISO

# Specialized images
nix build .#development-vm      # Full development environment
nix build .#development-minimal # Lightweight development VM
nix build .#production-server   # Hardened production server
nix build .#nixos-vm-builder-docker # Docker image for VM building

List all available images

nix flake show | grep "packages"

Available Deployment Images

Cloud Platforms

AWS AMI (aws)

Azure VHD (azure)

Digital Ocean Image (digitalocean)

Virtualization

VMware Image (vmware)

VirtualBox Desktop (virtualbox-desktop)

QEMU QCOW2 (qemu)

Containers

LXC Container (lxc)

Installation Media

Live ISO (iso)

Specialized Images

Development VM (development-vm)

Development Minimal (development-minimal)

Production Server (production-server)

VM Builder Docker (nixos-vm-builder-docker)

Deployment Factory Architecture

This template uses a deployment factory system (located in lib/deployment-images.nix) that provides:

Benefits

Factory Features

All images automatically include:

Platform-Specific Optimizations

Each image type includes platform-specific features:

Advanced Configuration

Custom Image Configuration

Create your own image variant by extending the base configuration:

# custom-image.nix
{ config, pkgs, ... }:
{
  imports = [
    ./hosts/common.nix
  ];

  # Your custom configuration
  services.myCustomService.enable = true;
  environment.systemPackages = with pkgs; [ customPackage ];
}

Then build with:

nixos-generate -f qcow -c ./custom-image.nix

Image Customization Options

All images include these base features:

Override Default Settings

# In your configuration.nix
{
  # Change default user
  users.users.nixos.initialPassword = "mypassword";

  # Enable monitoring
  modules.services.monitoring.enable = true;

  # Add custom packages
  environment.systemPackages = with pkgs; [
    myCustomPackage
  ];
}

Use Cases and Recommendations

Cloud Deployment

Local Development

Production Servers

Edge/IoT Deployment

Testing and Validation

Build Optimization

Parallel Building

# Build multiple images in parallel
nix build .#aws-ami .#azure-vhd .#gce-image --max-jobs auto

Caching Strategy

The template includes optimized caching:

Storage Requirements

Typical image sizes:

Deployment Examples

AWS EC2 Deployment

# Build AMI
nix build .#aws

# Upload to AWS (requires AWS CLI)
aws ec2 import-image --description "NixOS Template" --disk-containers "Description=NixOS,Format=vmdk,UserBucket={S3Bucket=my-bucket,S3Key=nixos.vmdk}"

Local VM Testing

# Build QCOW2 image
nix build .#qemu

# Run with QEMU
qemu-system-x86_64 -hda ./result/nixos.qcow2 -m 2G -enable-kvm

Development Environment Testing

# Build full development VM
nix build .#development-vm

# Build lightweight development VM
nix build .#development-minimal

# Run development VM
qemu-system-x86_64 -hda ./result/nixos.qcow2 -m 4G -enable-kvm -display gtk

Security Considerations

Default Credentials

SSH Access

Firewall

Updates

# After deployment, update system
sudo nixos-rebuild switch --upgrade
sudo nix-collect-garbage -d

Getting Started

  1. Choose your deployment target
  2. Build the appropriate image: nix build .#image-name
  3. Deploy following platform instructions
  4. SSH into system: ssh nixos@your-ip
  5. Change default password: passwd
  6. Customize configuration and rebuild

Additional Resources


Ready to deploy NixOS anywhere!