Skip to content

Instantly share code, notes, and snippets.

@kohane27
Forked from johnrichardrinehart/nixos_in_virtualbox.md
Last active March 10, 2024 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohane27/13b55069072d81de4aa140031b704bed to your computer and use it in GitHub Desktop.
Save kohane27/13b55069072d81de4aa140031b704bed to your computer and use it in GitHub Desktop.
NixOS from "scratch" as Virtualbox Guest

Steps

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

Run vim /mnt/etc/nixos/configuration.nix and set the below inside configuration.nix:

  1. Make sure boot.loader.grub.* are all commented out
  2. Include the following lines:
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;
  1. Exit configuration.nix
  2. Run nixos-install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment