Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to install NixOS from an Ubuntu liveCD

These are instructions for booting from an Ubuntu liveCD and installing NixOS on a machine. I needed to do this because the NixOS liveCD doesn't work on my machine (, so I'm just using the Ubuntu installation media as something to boot into.

Much of this is from discussion at

Get the Ubuntu ISO:

Write it to a USB drive with unetbootin

Boot from the USB drive

Open GParted

Create partitions:

  • name: boot
    file sytem: fat32
    size: 500 MB
  • name: swap
    file system: linux-swap
  • name: root
    file system: ext4

Open a terminal and sudo bash. You'll stay in this shell for the rest of the instructions.

Obtain the ISO.

ISO_URL=$(cat download.html | grep minimal | grep x86 | sed -r 's/.*"(.*\.iso)".*/\1/')
wget $ISO_URL -O nixos.iso

Mount the ISO.

mkdir nixos
mount -o loop nixos.iso nixos

Extract the Nix store. We won't fully install Nix in Ubuntu, but we'll use a few of the executables from the store.

mkdir /nix
unsquashfs -d /nix/store nixos/nix-store.squashfs

Find the relevant programs in the nix store and add them to PATH.

NIXOS_INSTALL=$(find /nix/store -path '*-nixos-install/bin/nixos-install')
NIX_INSTANTIATE=$(find /nix/store -path '*-nix-*/bin/nix-instantiate')
NIXOS_GENERATE_CONFIG=$(find /nix/store -path '*-nixos-generate-config/bin/nixos-generate-config')

Create the build group and a build user.

groupadd --system nixbld
useradd --system --home-dir /var/empty --shell $(which nologin) -g nixbld -G nixbld nixbld0

Obtain a copy of the Nix package repo and construct a NIX_PATH.

NIX_REV=$(echo $ISO_URL | sed -r 's~.*\.([0-9a-f]{7}).*~\1~')
wget$ -O
mv nixpkgs-* nixpkgs
export NIX_PATH=nixpkgs=$HOME/nixpkgs

Mount the partitions you created earlier. Note that your device names may differ from these.

mount /dev/sda3 /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot

Copy the nix store from the ISO into where the nix store will be on your new install. (This step isn't necessary, and I'm not sure if it actually helps, but it may spare you from needing to download some things.)

mkdir /mnt/nix
unsquashfs -d /mnt/nix/store nixos/nix-store.squashfs

Generate config files and install.

nixos-generate-config --root /mnt
nixos-install --root /mnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.