Skip to content

Instantly share code, notes, and snippets.

@wpiekutowski
Last active January 17, 2023 16:43
Show Gist options
  • Save wpiekutowski/2c067b121ceedc54fb5b655e7aebec57 to your computer and use it in GitHub Desktop.
Save wpiekutowski/2c067b121ceedc54fb5b655e7aebec57 to your computer and use it in GitHub Desktop.
Apple Virtualization NixOS ISO

Run NixOS ISO using Apple Virtualization framework (for example UTM)

  • local: Download ISO
    • 22.05 or build ISO: nix-build -A iso_minimal.aarch64-linux '<nixpkgs/nixos/release.nix>'
    • 22.11 Minimal 64-bit ARM
  • local: Mount hdiutil mount *.iso
  • local: Copy kernel and initrd: cp /Volumes/nixos-minimal-2?/boot/{Image,initrd} ..
  • local: Find and copy kernel params: less /Volumes/nixos-minimal-2?/EFI/boot/grub.cfg
  • local: Append console=hvc0 to params.
  • UTM: Create a new "drive". 16 GB is comfortable, 64 GB is plenty. Attach to your VM.
  • UTM: Attach the ISO.
  • UTM: Put kernel, initrd and set kernel params.
  • VM: Follow https://nixos.org/manual/nixos/stable/index.html#ch-installation. Partition with "Legacy Boot (MBR)" scheme to be able to use boot.loader.generationsDir. Later disable Grub as below:
  • VM: configuration.nix:
  # Switch to true if you want to check the current default kernel params. /boot/grub/grub.cfg will be created.
  boot.loader.grub.enable = false;
  boot.loader.grub.device = "nodev";
  
  # Creates /boot/default/kernel, /boot/default/initrd and a new subdirectory for each kernel and initrd upgrade under /boot. Makes it easier to copy these to host and simplify kernel params below.
  boot.loader.generationsDir.enable = true;
  
  # Recently started producing kernels unbootable by Apple Virtualization, so it's disabled until a fix can be found
  # boot.kernelPackages = pkgs.linuxPackages_latest;
  
  services.openssh = {
    enable = true;
  };
  • VM: nixos-install
  • VM: Enable root SSH login in your installation VM
  • local: copy new kernel and initrd from your new VM: scp root@vm:"/mnt/boot/nixos-{kernel,initrd}" .
  • VM: poweroff the installer
  • UTM: Use kernel, initrd and kernel params in VM's settings: console=hvc0 boot.shell_on_fail init=/boot/default/init loglevel=4
  • UTM: Boot your VM
@a-h
Copy link

a-h commented Oct 3, 2022

Brilliant, thanks, that worked. I upgraded to the latest NixOS ISO from the link, and updated to the latest nixos-kernel and nixos-initrd files, and I'm in!

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