Create a NixOS VM on Proxmox
This is a quick post outlining how to create a VM running NixOS on Proxmox.
Create VM
Download the Minimal ISO image from NixOS Downloads, then upload to your ISO image storage on one of your Proxmox nodes.
Create a VM with the following settings:
OS
- Use CD/DVD image file (iso) > ISO image: Select the NixOS Minimal ISO image.
System
- Machine: q35.
- BIOS: OVMF (UEFI) and select an EFI Storage location.
It is possible to boot in either legacy BIOS or UEFI (SeaBIOS or OVMF in this case within Proxmox), I chose UEFI here as it is supported in Proxmox, it’s the more modern implementation, and will benefit from faster boot times.
Storage
- 40GB or more.
- If you’re running low on space you can remove old packages and installations with
nix-collect-garbageor clear old generations of your system withsudo nix-collect-garbage --delete-old.
- If you’re running low on space you can remove old packages and installations with
CPU
- This depends on what you’re going to run but 1 socket and 2 cores is a good place to start.
Memory
- As above, but for an example let’s go with 4096 MB.
On the confirmation screen leave ‘Start after created’ unchecked and create the VM.
Head to Options and update the Boot Order so that the ISO image is at the top of the list (device ide2, for me).
Disable secure boot
When you first boot the machine it will say unable to boot.
BdsDxe: failed to load Boot0002 "UEFI QEMU DUD-ROM QM00003" from PciRoot (0x0) /Pci (0x1F,0x2) /Sata (0x1,0xFFFF,0x0) : Access Denied
BdsDxe: No bootable option or device was found.
Hit F2 to enter the boot menu and select EFI Firmware Setup. From here you need to disable secure boot. Follow Device Manager > Secure Boot Configuration and you’ll see Attempt Secure Boot will be checked. Hit SPACE to uncheck. Once done, leave the EFI Firmware settings and restart.
Next you’ll see the NixOS boot screen, it will automatically select the first option (LTS) after a few seconds then boot into a console.
Partitioning and formatting
The NixOS installer doesn’t do any partitioning or formatting, so you need to do that yourself.
Switch to root and list out the disks.
sudo -i
lsblk
You’ll see the 40GB disk called sda.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 1.5G 1 loop /mnt/.ro-store
sda 8:0 0 40G 0 disk
sr0 11:0 1 1.6G 0 rom /iso
Following the official docs, you will make 3 partitions:
- Root partition for a main disk storage (EXT4).
- This will fill the whole disk minus the following partitions.
- Swap partition (Linux swap):
- 4GB (go for the same as RAM)
- Boot partition (ESP (EFI system partition)):
- 512MB
# set partition style to GPT (GUID Partition Table)
parted /dev/sda -- mklabel gpt
# root
parted /dev/sda -- mkpart root ext4 512MB -4GB
# swap
parted /dev/sda -- mkpart swap linux-swap -4GB 100%
# boot
parted /dev/sda -- mkpart ESP fat32 1MB 512MB
parted /dev/sda -- set 3 esp on
Run lsblk to see the generated partitions:
[root@nixos:~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 1.5G 1 loop /nix/ro-store
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 35.8G 0 part
├─sda2 8:2 0 3.7G 0 part
└─sda3 8:3 0 487M 0 part
sr0 11:0 1 1.6G 0 rom /iso
Next format and mount the partitions:
mkfs.ext4 -L nixos /dev/sda1
mkswap -L swap /dev/sda2
mkfs.fat -F 32 -n boot /dev/sda3
# /mnt is the temporary mount point for the disk you are installing NixOS on to.
# After installation, and you reboot into NixOS, it will be mounted at /
mount /dev/sda1 /mnt
mount --mkdir /dev/sda3 /mnt/boot
swapon /dev/sda2
Run lsblk again to confirm the partitions have been mounted:
[root@nixos:~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 1.5G 1 loop /nix/.ro-store
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 35.8G 0 part /mnt
├─sda2 8:2 0 3.7G 0 part [SWAP]
└─sda3 8:3 0 487M 0 part /mnt/boot
sr0 11:0 1 1.6G 0 rom /iso
Installation
Run nixos-generate-config --root /mnt to generate your configuration.nix file.
root@Nixos:~# nixos-generate-config --root /mnt
writing /mnt/etc/nixos/hardware-configuration.nix...
writing /mnt/etc/nixos/configuration.nix...
For more hardware-specific settings, see https://github.com/NixOS/nixos-hardware.
Vim is included in the Minimal ISO image (thankfully!) so you can use that to edit the config:
vim /mnt/etc/nixos/configuration.nix
You don’t need to make any changes to the configuration at this stage, as once NixOS is installed and you’ve booted into it you can start configuring the new system. But it might help to install some basic system packages (Git, if you wanted to pull a configuration from a remote Git repository, for example).
Update the environment.systemPackages accordingly:
environment.systemPackages = with pkgs; [
vim
wget
git
];
Now to install NixOS:
nixos-install
At the end you’ll be asked to set a root password.
Now shutdown the machine and remove the ISO image from VM > Options > Boot Order. Then start up the VM.
Once booted, you can edit the config file by running vim /etc/nixos/configuration.nix followed by nixos-rebuild switch to apply the updates to the system.
And that’s done! 🎁
Configuration
Here’s an example of a basic configuration.nix which contains a user and ssh access
{ config, lib, pkgs, ... }:
{
imports = [
./hardware-configuration.nix
];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
users.users.alice = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
};
environment.systemPackages = with pkgs; [
vim
wget
cifs-utils
];
services.openssh = {
enable = true;
hostKeys = [
{
comment = "nixos";
path = "/etc/ssh/ssh_host_ed25519_key";
type = "ed25519";
}
];
};
system.stateVersion = "25.05"; # make sure this matches the version generated by nixos-generate-config above
}
You can find my NixOS config here to see the setup for my homelab.