Skip to content

Instantly share code, notes, and snippets.

@johnrichardrinehart
Last active July 11, 2024 22:26
Show Gist options
  • Save johnrichardrinehart/239b305d61b1c378ab84473ff8508cc1 to your computer and use it in GitHub Desktop.
Save johnrichardrinehart/239b305d61b1c378ab84473ff8508cc1 to your computer and use it in GitHub Desktop.
NixOS from "scratch" as Virtualbox Guest

Steps

New VirtualBox Machine

  1. Create a new disk image (I use VDI for compatibility with VirtualBox)
  2. Allocate some RAM (>6 GiB to start)
  3. Add some video memory and enable 3D acceleration, if needed
  4. Optional: Enable EFI (instead of BIOS)
  5. Attach nixos-minimal ISO for installation
  6. Boot into the ISO

Inside the Live CD

UEFI instructions

sudo su # assume root
parted /dev/sda -- mklabel gpt
parted /dev/sda -- mkpart primary 512MiB -8GiB
parted /dev/sda -- mkpart primary linux-swap -8GiB 100%
parted /dev/sda -- mkpart ESP fat32 1MiB 512MiB
parted /dev/sda -- set 3 esp on
mkfs.ext4 -L nixos /dev/sda1
mkswap -L swap /dev/sda2
mkfs.fat -F 32 -n boot /dev/sda3
mount /dev/disk/by-label/nixos /mnt
mkdir -p /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot
swapon /dev/sda2
nixos-generate-config --root /mnt
vim /mnt/etc/nixos/configuration.nix
# set the below inside the configuration.nix
# make sure that `boot.loader.grub.*` are all commented out
## boot.loader.systemd-boot.enable = true;
## boot.loader.efi.canTouchEfiVariables = true;
## boot.loader.timeout = 2;
## nix = {
##    package = pkgs.nixUnstable;
##    extraOptions = "experimental-features = nix-command flakes";
## };
## virtualisation.virtualbox.guest.enable = true;
nixos-install # now, wait a while
@lalishansh
Copy link

nix.package = pkgs.nixUnstable;
should be changed to
nix.package = pkgs.nixVersions.latest;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment