NixOS on AWS: Complete Setup Guide for Base NixOS 25.05 AMI¶
Most NixOS tutorials assume you'll install from scratch and figure out the rest. That's a 2-hour detour into dependency conflicts and broken configurations.
There's a faster way: use a prebuilt AMI that boots into a working NixOS system in under 5 minutes.
This tutorial walks through launching the Base NixOS 25.05 AMI on AWS EC2, verifying it works, and making your first declarative configuration change.
Prerequisites¶
Before starting:
- An AWS account with EC2 access
- An EC2 key pair (ECDSA recommended, RSA is deprecated on modern NixOS)
- Basic familiarity with SSH
No NixOS experience required. That's the point.
Step 1: Subscribe to the AMI¶
- Go to the Base NixOS 25.05 listing on AWS Marketplace
- Click Continue to Subscribe
- Accept the terms
- Click Continue to Configuration and select your region
The AMI is free—AWS charges only for the EC2 instance you launch.
Step 2: Launch the Instance¶
From the AWS Marketplace:
- Click Launch
- Choose an instance type (t3.small is fine for testing, m5.large for production)
- Select your key pair
- Configure security group: allow SSH (port 22) from your IP
- Click Launch
Wait 30-60 seconds for the instance to initialize.
Step 3: Connect via SSH¶
You're in. The system is running NixOS 25.05 with:
- Firewall enabled
- Password authentication disabled
- Root login disabled
- Only essential services running
Check the NixOS version:
You should see NixOS 25.05 in the output.
Step 4: Explore the Configuration¶
The entire system state is defined in one file:
This is the declarative configuration. Every installed package, every service, every setting—defined here. Not accumulated over time through manual commands.
The AMI comes with a minimal setup:
- SSH server (hardened)
- Firewall (enabled by default)
- ec2-user with sudo privileges
- Cloud-init for automated bootstrapping
Step 5: Make a Change¶
Let's install a package to see the declarative workflow in action.
- Edit the configuration:
- Add a package to the
environment.systemPackageslist:
- Apply the change:
NixOS downloads the packages, builds the new system configuration, and switches to it atomically. No partial installs, no broken dependencies.
- Verify:
All three are installed. If you hadn't added them, they wouldn't exist—there's no hidden state.
Step 6: Test a Rollback¶
This is where NixOS earns its reputation.
Something broken? Roll back to the previous configuration:
Instant. The packages you just added are gone. The system is exactly as it was before.
This isn't a backup restore. It's a zero-cost operation that takes seconds—NixOS keeps previous generations available by default.
What's Preconfigured¶
The Base NixOS 25.05 AMI includes these security hardening measures:
| Feature | Status |
|---|---|
| Firewall | Enabled |
| SSH password auth | Disabled |
| Root SSH login | Disabled |
| Default user | ec2-user (sudo) |
| ECDSA keys | Supported (RSA deprecated) |
| Cloud-init | Compatible |
| Desktop | XRDP + KDE Plasma ready |
You don't need to harden anything. It's production-ready from first boot.
Optional: Enable Remote Desktop¶
The AMI includes XRDP + KDE Plasma support. To enable it:
- Edit
/etc/nixos/configuration.nix - Uncomment the XRDP line (look for the xrdp comment block)
- Rebuild:
- Set a password for
ec2-user:
- Connect via RDP client to your instance's public IP
This gives you a full graphical desktop environment on a cloud instance—useful for development, testing, or running GUI applications remotely.
Next Steps¶
Now that you have a working NixOS instance:
- Define services: Add Nginx, PostgreSQL, or Docker as declarative services in
configuration.nix - Version control: Commit your
configuration.nixto Git for full infrastructure history - Scale: Use the same configuration file to launch identical instances
- Integrate: Pair with Terraform or Pulumi for complete infrastructure as code
The NixOS manual covers the full configuration reference.
Why This AMI¶
Building NixOS from scratch takes 1-2 hours. This AMI skips that entirely:
- Pre-hardened: Security best practices applied at build time
- Minimal footprint: Only essential services running
- Cloud-optimized: Designed for EC2 with cloud-init support
- Up-to-date: Based on NixOS 25.05 stable release
For teams evaluating NixOS on AWS, this is the fastest path from "interested" to "running in production."
Launch the AMI: Base NixOS 25.05 on AWS Marketplace