NixOS on Proxmox LXC Setup

September 19th, 2023 · 2 min

This guide will explain how to install NixOS in an LXC container in Proxmox.

Getting an LXC container template into Proxmox

A template can either be downloaded from the Nix pipeline, or built using the Proxmox LXC community generator. This file needs to be uploaded to Proxmox as a CT template.

Downloading an image

Download the latest nixos-system-x86_64-linux.tar.xz image from the Nix pipeline.

Then upload the CT template using the Proxmox web GUI.

CT upload

Building an image (Alternative)

If there’s an issue with the pre-built image, or the base configuration needs to be changed, you can build your own template using Nix.

To generate a Proxmox LXC template, you will need to have a system with Nix installed. You can install NixOS in a VM or on a spare machine using the NixOS ISO, or install Nix on an existing Linux or MacOS machine using the determinate Nix installer, which is supported on Windows via WSL as well.

Generate the template.

$ nix run github:nix-community/nixos-generators -- --format proxmox-lxc

Or customize the initial image by providing your own configuration.nix. You can install additional packages, change the default root password, etc.

$ nix run github:nix-community/nixos-generators -- --format proxmox-lxc -c ./configuration.nix

Take note of the file path output at the end. This is the file that needs to be uploaded to Proxmox.

Then upload the CT template using the Proxmox web GUI.

CT upload

Create an LXC Container

Create a new LXC container using the uploaded template in the web GUI.

Currently (as of 2023/09), the default Proxmox web console is broken with NixOS. To fix this, change the container’s Console mode from tty to console. If the container is already started, restart it to get the console working.

Start the container, and open the console. It may still be blank, however the login prompt should appear after pressing enter.

Enter root for the username and nixos for the password, unless it was changed in the custom image.

Go ahead and set a new root password now, if you haven’t already.

# password
New password: 
Retype new password: 
passwd: password updated successfully

Initialize nixpkgs.

# nix-channel update
unpacking channels...

Initialize /etc/nixos/configuration.nix using this minimal example.

# cat > /etc/nixos/configuration.nix <<EOF
{ modulesPath, ... }: {  
  imports = [ (modulesPath + "/virtualisation/proxmox-lxc.nix") ];  

Apply any newer changes since the template was created and reboot.

# nixos-rebuild switch
building Nix...
building the system configuration...
# reboot


After completing these steps, you will have a NixOS Proxmox LXC up and running!