Gabriella439 / nixos-in-production

Source files for the book "NixOS in Production"
Other
484 stars 20 forks source link

Error running NixOS virtual machine on aarch64-darwin #20

Open Velnbur opened 1 year ago

Velnbur commented 1 year ago

Steps to reproduce

  1. Got nixpkgs installed as package manager for my macOS M2 machine (Ventura 13.4)
  2. Start linux builder: nix run 'nixpkgs#darwin.linux-builder' in one terminal
  3. Initialize nix flake from template: nix flake init --template 'github:Gabriella439/nixos-in-production/0.6#setup on host machine
  4. Run nix run on host machine, got an error:
trace: warning: system.stateVersion is not set, defaulting to 22.11. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion.
error: a 'aarch64-linux' with features {} is required to build '/nix/store/7x9vvn81v5v5d5d4wiv97mf1kpsykd93-append-initrd-secrets.drv', but I am a 'aarch64-darwin' with features {benchmark, big-parallel, nixos-test}
Gabriella439 commented 1 year ago

It looks like Hydra's cache might not be populated, yet, but I'll fix the instructions to reference an older (pinned) version of the builder.

In the meantime, I believe you can work around this problem by running:

$ nix run 'github:NixOS/nixpkgs/23.05#darwin.builder'

… and updating the rest of your configuration to match the instructions from this version of the manual: https://nixos.org/manual/nixpkgs/stable/#sec-darwin-builder

I'm essentially going to be updating the book to say the same thing.

gilacost commented 1 year ago

I tried to start the linux builder in one terminal and it won't start:

❯ nix run 'github:NixOS/nixpkgs/#darwin.linux-builder'
Formatting '/tmp/nix-vm.AXuTUxIF5k/store.img', fmt=qcow2 cluster_size=65536 extende
d_l2=off compression_type=zlib size=1285554176 backing_file=/nix/store/11rf9pfn70qi
wvh1y7jv4sr0mvxlrcg3-nixos-disk-image/nixos.qcow2 backing_fmt=qcow2 lazy_refcounts=
off refcount_bits=16
[    0.078541] armv8-pmu pmu: hw perfevents: failed to probe PMU!

<<< NixOS Stage 1 >>>

loading module virtio_balloon...
loading module virtio_console...
loading module virtio_rng...
loading module dm_mod...
running udev...
Starting systemd-udevd version 253.6
kbd_mode: KDSKBMODE: Inappropriate ioctl for device
starting device mapper and LVM...
waiting for device /dev/disk/by-label/nixos to appear.......................
Timed out waiting for device /dev/disk/by-label/nixos, trying to mount anyway.
mounting /dev/disk/by-label/nixos on /...
[   21.939051] /dev/disk/by-label/nixos: Can't open blockdev
mount: mounting /dev/disk/by-label/nixos on /mnt-root/ failed: No such file or dire
ctory

An error occurred in stage 1 of the boot process, which must mount the
root filesystem on `/mnt-root' and then start stage 2.  Press one
of the following keys:

  r) to reboot immediately
  *) to ignore the error and continue

If I try to run it with a most up to date nixpkgs version as you suggested it complaints about not being able to set up the port forwarding:

❯ nix run 'github:NixOS/nixpkgs/23.05#darwin.builder'  
Formatting '/tmp/nix-vm.4402DYK4ib/store.img', fmt=qcow2 cluster_size=65536 extende
d_l2=off compression_type=zlib size=1250951168 backing_file=/nix/store/0rq0q84l6wlg
r0nmlwly4ywi2lfk1n77-nixos-disk-image/nixos.qcow2 backing_fmt=qcow2 lazy_refcounts=
off refcount_bits=16qemu-system-aarch64: -netdev user,id=user.0,hostfwd=tcp::22-:22,: Could not set up 
host forwarding rule 'tcp::22-:22'
gilacost commented 1 year ago

Okay, it looks like ventura 13.0 Enables remotelogin by default, or at least it was enabled on my system. If anyone encounters this, you can turn remote login off with sudo systemsetup -setremotelogin off. This will ensure that the VM starts: nixos vm start

But then when running nix run in another shell it produces the error that Velnbur mentioned:

aarch error

gilacost commented 1 year ago

I followed exactly your instructions and it works @Gabriella439 ❤️ ! For anyone that lands on this Issue:

1). Try to start the builder once with nix run 'github:NixOS/nixpkgs/23.05#darwin.builder', you need to do this in the same folder that you have done the nix flake init --template 'github:Gabriella439/nixos-in-production/0.6#setup' 1.2). If you have issues with the port already being allocated disable remote login if you have it enabled via sudo systemsetup -setremotelogin off 2). Once you have started the builder and sutted it down with shutdown now all subsequent builders start should be done via nix run in the folder you have the flake. 3). Update the nix.conf including a builder section as explained in here, you can see an example in my dot-files

❤️ ❤️ ❤️ ❤️