nix-community/nixos-anywhere

How can I load the image in a VM?

madorian opened this issue · 6 comments

In the tutorial, step 7, it says it can test the image in a VM.

Can I also connect to this local VM?

I want to see that the image works the way I expect it to, in a VM.

Yes. Step 7 in the Quickstart tells you the command to run the VM. Does that work for you and is this issue only about the question of how to get a shell there?

If so, and if your config has got SSH enabled, you can use --impure (to allow access to the local environment) and QEMU_NET_OPTS to forward SSH from port 22 in the VM to port 2222 locally.

i.e. something like

QEMU_NET_OPTS="hostfwd=tcp::2222-:22" nix --impure run github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> --vm-test

ssh -p 2222 root@localhost 

should work

Right, but how about if the image has Xorg and you want to inspect the WM configuration, etc?

the --vmtest builds "${flake}#nixosConfigurations."${flakeAttr}".config.system.build.installTest", a nixos test configuration from disko under the hood to check the installation process.
If you want to run an automated test, make sure that https://search.nixos.org/options?channel=23.11&show=virtualisation.graphics is set to true

if you want to check it interactively, the straightest way here might be to use a normal nixos vm, i.e.
`
QEMU_NET_OPTS="hostfwd=tcp::2222-:22" nix --impure run .#nixosConfigurations.$host.system.build.vm

`

ok, I'm on deep water here, so how would the actual command look like for your nixos-anywhere examples?;)

I assume this $host is a placeholder for the hostname in the config file?

QEMU_NET_OPTS="hostfwd=tcp::2222-:22" nix --impure run .#nixosConfigurations.$host.system.build.vm```

If I run it verbatim, except --impure is an argument to run:

BASHY $ QEMU_NET_OPTS="hostfwd=tcp::2222-:22" nix run --impure .#nixosConfigurations.$host.system.build.vm
warning: Git tree '/home/b0ef/repoman/2024-01-07.nixos-anywhere-example/nixos-anywhere-examples' is dirty
error: flake 'git+file:///home/b0ef/repoman/2024-01-07.nixos-anywhere-example/nixos-anywhere-examples' does not provide attribute 'apps.x86_64-linux.nixosConfigurations..system.build.vm', 'packages.x86_64-linux.nixosConfigurations..system.build.vm', 'legacyPackages.x86_64-linux.nixosConfigurations..system.build.vm' or 'nixosConfigurations..system.build.vm'

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-can-i-build-a-vm-image-with-nix-deployment-tools/38605/1