Skip to content

Instantly share code, notes, and snippets.

@wpiekutowski
Last active January 17, 2023 16:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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 Sep 11, 2022

For reference, in the grub.cfg file, I found params inside the menuentry:

    menuentry 'NixOS 22.05.2994.15493135c0a Installer '  --class installer {
  linux /boot/Image ${isoboot} init=/nix/store/jnmkxmq9sipxqs4qmnjjc0f8kv9pv30s-nixos-system-nixos-22.05.2994.15493135c0a/init console=ttyS0,115200n8 root=LABEL=nixos-minimal-22.05-aarch64 boot.shell_on_fail loglevel=4 
  initrd /boot/initrd
}

I could get the machine to boot with this (note the console=hvc0 appended at the end):

  linux /boot/Image ${isoboot} init=/nix/store/jnmkxmq9sipxqs4qmnjjc0f8kv9pv30s-nixos-system-nixos-22.05.2994.15493135c0a/init console=ttyS0,115200n8 root=LABEL=nixos-minimal-22.05-aarch64 boot.shell_on_fail loglevel=4 console=hvc0

It is configured in UTM at
image

@a-h
Copy link

a-h commented Sep 11, 2022

I downloaded the installation ISO from hydra.

nixos.iso_minimal.aarch64-linux

There's a list of build outputs at: https://hydra.nixos.org/jobset/nixos/release-22.05-aarch64#tabs-jobs

@wpiekutowski
Copy link
Author

Thanks! I updated the gist with this link and some configuration.nix tips.

@a-h
Copy link

a-h commented Oct 2, 2022

I've tried to get this working for a few hours, and still failed.

The NixOS install instructions say to use:

parted /dev/sda -- mklabel msdos

But on my machine, vdb is the one to use for boot (vda is not writeable).

image

Making the filesystems

image

Creating the config

image

Using example configuration above

image

nixos-install

image

Afterwards, it looks right

image

And I've updated the VM to use the NixOS kernel

image

But...

image

If anyone can fill in the gaps of the process, that would be great!

@wpiekutowski
Copy link
Author

@a-h recently boot.kernelPackages = pkgs.linuxPackages_latest; started producing kernels that don't work with Apple Virtualization framework. Reverting to the default kernel by removing this line works. I'm not sure what might be causing this, as until recently 5.19 Linux kernels were fine. I suspect something could have been changed in the way kernel Nix package is built, but I haven't got time to properly investigate.

@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