Bash shell for nixos test machine

Is it possible to get a bash prompt for a machine defined in a nixos test?
I am aware that you can run:

$ nix-build -A driver ./test.nix
$ ./result/bin/nixos-test-driver
> startAll
> $machine->succeed("echo hey")

But the perl wrapping of bash commands gets annoying very vast.

Also in NixOS - NixOS 21.05 manual it states:

The script nixos-run-vms starts the virtual machines defined by test.

That’s not very clear and --help doesn’t work on it.
What is it supposed to do?

1 Like

Help yourself, have you tried to run it? it’s pretty self explanatory. :wink:

Inside the NixOS tests the machines are accessible through perl variables and DNS records.
nixos-run-vms just starts the machines but doesn’t give me a prompt or something to interact with them. so what is it good for? are the machines exposed somewhere?

If you are running nixos-run-vms from an X11 terminal it should open one window per VM showing the console, where a normal login prompt should appear. I never tried it from a non-graphical terminal, I suppose there is some option to add some kind of redirection to the VMs I/O, but I don’t know the details.

1 Like

Yes, I guess that’s the issue.
I’m running everything on a linux server over ssh cause my local machine is a mac and tests are not supported on darwin.

Since you posted this I’ve discovered that if you set and export an environment variable named QEMU_OPTS, its value will be added to the Qemu command line, but I haven’t yet figured out how to connect to the test machine, have you?

Better, use something linke QEMU_NET_OPTS="hostfwd=tcp::10022-:22"

Previous to Revert "Add ssh backdoor to VM tests infrastructure." · NixOS/nixpkgs@3aab228 · GitHub there was a way to hack into test machine. Unfortunately, it was reverted due to some conflicts with Hydra CI…

You may try to revert that revert and try to socat into machine.

Does that still work for you? I am running it from an X11 terminal (urxvt) and it is not opening any windows.

What worked for me is setting the QEMU_OPTS environment variable to -display gtk before running the command to start the VMs.

There is some logic that runs inside the build sandbox and sets -nographic (see on github), which is why I think that workaround is necessary. If that’s an error I’m not sure yet how to fix it.

I just opened an issue about this: nixos/test-driver: It's to difficult to get dedicated windows for each VM under test · Issue #144742 · NixOS/nixpkgs · GitHub