Richard Bucker

VirtualBox, Vagrant and NixOS

Posted at — Jan 24, 2015

Most Linux versions, and possibly all Unix variants, provide a customizable welcome message when logging in and one of the things I have come to expect is the IP address in the message. This is especially useful when using VirtualBox or VMware. However, if you’re running headless and you’re not publishing your guests IP address to a local DNS server then things are going to get a bit challenging.One of the features I like when using Vagrant is that you can get the IP address of the current guest with a command: vagrant ip. Of course the vagrant config has to be in the cwd so that can be a challenge. And there can be more than one instance too… so bouncing between guest folders is a nuisance.Here is a NixOS/Vagrant plugin that should be helpful. I also found this article with a couple of sample commands for VirtualBox like:VBoxManage guestproperty get NixOS “/VirtualBox/GuestInfo/Net/0/V4/IP"And since I also had a local-only IP address I needed to execute this to get that IP:VBoxManage guestproperty get NixOS “/VirtualBox/GuestInfo/Net/1/V4/IP"I suppose there could be a wildcard value to stick in there, however, it’s still very difficult to infer which device is hosting which port… but it’s still some good info.And then there is my new favorite command. ┬áStarting the machine in headless mode.VBoxManage list vmsVBoxHeadless –startvm NixOS"NixOS” is the name I have my guest and it is in the list from the ‘list vms’ command.UPDATE: this is not the polite way to start a guest because it (a) runs in the foreground, and (b) when shutdown inside the guest the command does not terminate. This is less than ideal behavior and requires investigation. There is a way to launch a guest headless from the VirtualBox GUI(shift+double-click).